Skip to main content
Question

Create Lines from Point based on past features

  • February 27, 2015
  • 2 replies
  • 6 views

Forum|alt.badge.img
Hello,

 

I want to create lines from points based on the following:

 

 

1) Each feature contains an attribute with one of the following value: 

 

A+, A or A-

 

2) Feature with A+ means start of the line

 

3) Feature(s) with A mean means continuation of the line. 

 

4) A- means end of the line. 

 

5) Another A+ means it will start a new line. 

 

 

I know I can use point connector to connect the points. But, I am having a hard time on creating and then keeping it connected until I encounter A- to break it. 

 

 

Any ideas?

 

 

2 replies

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • February 28, 2015
Hi,

 

 

These approaches flashed in my mind.

 

 

1. AttributeCreator with the "Prior/Subsequent Feature Attribute Retrieval (Multiple Feature Attribute Support)" option and the "Conditional Value" setting

 

(1) AttributeExposer

 

Attribute To Expose: _line_id

 

(2) AttributeCreator

 

Number of Prior Features: 1

 

If Attribute is Missing, Null, or Empty: Use Fallback Value

 

Fallback Value: 0

 

Attributes To Set (Conditional Value Setting):

 

_line_id = If _attr = A+ Then feature[-1]._line_id + 1 Else feature[-1]._line_id

 

(3) PointConnector (Connection Break Point: _line_id)

 

 

 

2. VariableSetter/VariableRetriever

 

(1) Sampler

 

Sampling Type: First N Features

 

Sampling Amount: 1

 

(2) VariableSetter (for the "Sampled" feature, i.e. the first feature)

 

VariableName: vLineId

 

Value: 1

 

(3) VariableRetriever (for every feature)

 

VariableName: vLineId

 

Attribute ReceivingValue: _line_id

 

(4) VariableSetter_2

 

VariableName: vLineId

 

Value (Conditional Value setting):

 

If _attr = A- Then _line_id + 1 Else _line_id

 

(5) PointConnector (Connection Break Point: _line_id)

 

 

 

3. PythonCaller

 

-----

 

class FeatureProcessor(object):

 

    def __init__(self):

 

        self.line = None

 

        

 

    def input(self, feature):

 

        attr = feature.getAttribute('_attr')

 

        if attr == 'A+': # start

 

            self.line = feature

 

        elif self.line != None:

 

            self.line.addCoordinate(*feature.getCoordinate(0))

 

            if attr == 'A-': # end

 

                self.pyoutput(self.line)

 

                self.line = None

 

-----

 

 

Takashi

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • February 28, 2015
Regarding the VariableSetter/Retriever approach, this may be smarter than the previous one.

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings