Hexagon Geospatial
MENU

ERDAS IMAGINE

Discuss and share topics of interest using ERDAS IMAGINE the world’s leading geospatial data authoring system.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
Regular Contributor
Posts: 205
Registered: ‎11-16-2015
Accepted Solution

Combine attributes with same id

Hi,

 

I have a shapefile with attributes like this

 

ID       Value

1          10

2          20

3          15

1          12

2          21

3          14

 

I'd like to get the mean of the values for ID 1,2 and 3. Any bright ideas how to do this in spatial modeler? 

 

Cheers,

 

Johnne

Regular Contributor
Posts: 205
Registered: ‎11-16-2015

Re: Combine attributes with same id

Suplemental and possibly related. Using the merge feature operator, how can the ID be passed through so that it relates to the original ID? Using this I can merge features using merge matching attributes, but if I match attribute ID what's the syntax in the functional attribute to pass this through to the output features?

Staff
Posts: 115
Registered: ‎07-04-2016

Re: Combine attributes with same id

Hi Johnnie,

 

If I got you correctly and you want mean value separately for each ID, so the model will look like below:

 

2018-09-11 10_33_00-New notification.png

Kind Regards,
Marina Vardovska
Hexagon Geospatial Support
Staff
Posts: 115
Registered: ‎07-04-2016

Re: Combine attributes with same id

Hi Johnnie,

 

Regarding your second question, as you are merging few features into one, you need to specify the function how their attributes will be merged via the Functional Attributes (Double-click on Summary Attribute port). In my example, features were merged using common ID, so I can use any Statistical function - MIN, MAX, AVERAGE - as that ID will be the same for merged features.  

 

2018-09-13 11_24_32-Start.png

 

2018-09-13 11_45_55-Start.png

Kind Regards,
Marina Vardovska
Hexagon Geospatial Support
Regular Contributor
Posts: 205
Registered: ‎11-16-2015

Re: Combine attributes with same id

Hiya. That would work if the IDs were numerical, but I'm afraid I have a string id. Any idea what I could use for that? 

Technical Evangelist
Technical Evangelist
Posts: 289
Registered: ‎02-03-2016

Re: Combine attributes with same id

You have correctly identified the new/improved Merge Features operator as the right tool, and attribute-based merge as the right Criteria.  To make sure the ID that was used as the basis of the merge is carried through to the output Features, just use the FIRST expression function.  Because each set of feature instances being merged shares a common ID, any one of them will do, so the FIRST function essentially just says "grab any one of the ID values for this set" :-).  Your two functional attributes would look like this:

 

ID=FIRST(FeaturesIn.ID)

AverageValue=AVERAGE(FeaturesIn.Value)

 

- Hal

Regular Contributor
Posts: 205
Registered: ‎11-16-2015

Re: Combine attributes with same id

Thanks guys; that seems to have done the job perfectly. 

Regular Contributor
Posts: 205
Registered: ‎11-16-2015

Re: Combine attributes with same id

Hi again,

 

In best Columbo style, there's just one more thing...

 

In my original example, I had data thus:

 

ID       Value

1          10

2          20

3          15

1          12

2          21

3          14

 

I'd like to bring the original values over as well to the new combined feature dataset, so as to have:

 

ID      Mean    Value 1     Value 2

1           11         10              12

2          20.5       20              21

3          14.5       15              14

 

I was thinking that Choose might be the function to use but it doesn't seem happy.

 

Thanks,

 

Johnnie

Technical Evangelist
Technical Evangelist
Posts: 289
Registered: ‎02-03-2016

Re: Combine attributes with same id

Because you can have a variable number of values per output feature, your proposed approach would require a variable number of output fields, which is not possible.  The closest you can come would be to concatenate the values into a single text field.  For this you can use the following:

 

CONCATENATE(',', FeaturesIn.Value)

 

This will concatenate all the values together, separated by commas.  I cannot remember if you have to convert non-text values to text first, I think you do.  In this case you can wrap the reference to the Value field within a TEXT function specifying the formatting you prefer.

 

- Hal

Regular Contributor
Posts: 205
Registered: ‎11-16-2015

Re: Combine attributes with same id

Thanks for that Hal. I was hoping that as there was a FIRST and LAST operator, there might be something that would enable us to get intermediate values as well. 

 

I don't think it would be a variable number of values per feature - in that example there are two points per ID that would give two new attributes to the output.

 

Cheers,

 

Johnnie

Polls
Please register to vote
Do you need immediate support?
If you encounter a critical issue and need immediate assistance please submit a Service Request through our Support Portal.