Hexagon Geospatial
MENU

Smart M.App

Looking for answers in regards to M.Apps, M.App Exchange or M.App Studio? Smart M.App Tech Discussion board is where you can search, ask your questions and assist others by sharing your knowledge. Join the conversation, connect, contribute and share.
Showing results for 
Search instead for 
Do you mean 
Reply
Occasional Contributor
Posts: 8
Registered: ‎09-05-2016

How to update an attribute for a subset of a Feature file

Hi I've got a newbie question about how Feature filtering/updating operators work:
 
I've been trying to create a spatial recipe that would load a shape file, perform some calculations, update an attribue on a subset of the geomerties in a file, then save the file back again.

Although I thought I could see how this would be done by using FilterByGeometry and UpdateAttribute but I'm stuck when combining updated FeatureSubset into the old non-filtered Features.

Perhaps I'm misunderstanding how this works but I assume if I simply save the resulting FeatureSubset from the output of the UpdateAttribute node I think I'll lose all the geometries filtered out by FilterByGeometry - this isn't what I want, I want an in place update, so what operator do I use to combine the updated features with the unaltered features before I save the features with a FeaturesOutput node so I can avoid filtering out the geometries I don't want to update?
 
So for example, say I have a Features file with 20 geometries and the atrributes "id" and "value" lets say I want to update the attribute "value" of the row with the "id" 11 (but leave the others untouched) how would I create that recipe?
 
Hope that makes sense, 
 
Michael
 
 

Technical Evangelist
Posts: 532
Registered: ‎09-11-2015

Re: How to update an attribute for a subset of a Feature file

Hi Michael,

 

I was also unable to figure out how to achieve this. I was thinking of two ways. The first one is similar to what you are trying to do. In the simplfied case, filter the feature with ID=11, update the VALUE attribute, this should be viable. Then you could filter feature with ID <> 11, but there is no way to merge the two FeatureSubsets together (there is no Union operator or anything like that).

 

The other option would be to select attribute ID into table 1, select attribute VALUE into table 2, find index of 11 in table 1 - this is still possible, but then how to update the value in table 2 at the index found in the previous step? This seems to be impossible.

 

I was also looking at Dictionaries, but it does not seem to be the right way either. So I would say that your task has no solution with the current implementation. Needless to say that it would all be even more complicated with spatially filtered FeatureSubsets.

 

But perhaps someone else will come with a solution.

 

Pavel

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

Re: How to update an attribute for a subset of a Feature file

Hello Machael,

 

If I got you right the following model should help or at least push to some idea. 

 

model.png

 

Here I am selecting MEAN_1 column which have value of 0.444213 and using Either/Or operator to update MEAN column with this value in a corresponding row. And then updating an attribute in a feature.

 

The only thing you must make sure is that your columns must have the same format.

 

So before I had following columns (0.444213 value is in row 5):

 

fields.png

 

After processing I got value of 0.444213 replaced in the MEAN column of a corresponding row.

 

update.png

 

Hope this will help. 

 

Kind Regards,

Marina Vardovska
Post-Sales Engineer Remote Sensing

Hexagon Geospatial Division

Kind Regards,
Marina Vardovska
Hexagon Geospatial Support
Highlighted
Frequent Contributor
Posts: 77
Registered: ‎10-12-2015

Re: How to update an attribute for a subset of a Feature file

[ Edited ]

This should also help. Based on mardovs' reply, I managed to make a model with a proper query for the exact row. The table updates the exact row properly, however, the update attribute port fails for me. Anyway, this should be the gist of it, so give it a try - it might work for you: 

 

 

The Filter is the attribute by which you want to filter, the row is the value of the before mentioned filter (the one you want to get to), the attribute is the attribute which you want to change and the value is what you want to change it with. Hope this helps.

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

Re: How to update an attribute for a subset of a Feature file

[ Edited ]

RaduConst,

 

Perfect modification. If to update the specified row of a selected column with some value, so your model works perfectly. There is no need to add Custom Table Input when you specify the correct format in Either/Or operator.

 

update_1.png 

 

Thank you.

 

Regards,

Marina

Kind Regards,
Marina Vardovska
Hexagon Geospatial Support
Occasional Contributor
Posts: 8
Registered: ‎09-05-2016

Re: How to update an attribute for a subset of a Feature file

[ Edited ]

Excellent, those example models make things a lot clearer. Unfortunately, even though the model seems to run properly the features file that is output still has the old values? (I'm using Imagine spatial modeller not the web spatial modeller for now) 

 

My model looks like this:

The paddocks input has a single row with "id" set to 1 and two columns "yieldTotal" and "yieldGoal" both are initally set to 1.0 and I'm expecting the yieldTotal to be set to 0.562 afterwards in paddocks2.shp but I'm seeing the original value unmodified. Any ideas what I'm doing wrong ?

 

BTW: This is the attributes table of paddocks2.shp, oddly there are two extra columns added "PrimaryKey" and "PrimaryKey1":

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

Re: How to update an attribute for a subset of a Feature file

Hello michael,

 

Could you please attach here your model together with a shapefile you are using as an input?

 

From a screenshot I don't see any problem, it should work. So let me have a look at your data. You can send it in private message if don't want to publish.

 

Thank you.

 

Regards,

Marina

Kind Regards,
Marina Vardovska
Hexagon Geospatial Support
Frequent Contributor
Posts: 77
Registered: ‎10-12-2015

Re: How to update an attribute for a subset of a Feature file

Yes, for some reason this happens to me too, everything works fine, the table gets updated, but when the features are updated - nothing happens. It's like that one update attribute operator revolts against the spatial model.

Occasional Contributor
Posts: 8
Registered: ‎09-05-2016

Re: How to update an attribute for a subset of a Feature file

Yep sure, I've attached my shape file and model. Note I've changed the model to have a seperate in and out filename because in another model I found that trying to overwriting a file used as input can cause problems (although it did seem to work in this case - I hoped it was the problem but my attributes still aren't being updated). updateattr.gmdx  paddocks.shp

 

Michael

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

Re: How to update an attribute for a subset of a Feature file

Dear Michael,

 

I found the solution. Now investigating on "why it works like that" and soon will create a CR-Deffect.

 

Your model definitely doesn't work. But try to change the column name (replace the old one or just add new one) to some with all uppercases. For example: was – yieldTotal, become YIELDTOTAL.

 

And run the model:

 

update12092016.png

 

The attribute table will be updated:

 

updated12092016.png

 

Kind Regards,

Marina Vardovska
Post-Sales Engineer Remote Sensing

Hexagon Geospatial Division

 

Kind Regards,
Marina Vardovska
Hexagon Geospatial Support
Do you need immediate support?
Please submit a Ticket through our
Development Ticket Portal.