Skip to main content
Hi FMErs

 

 

I have a .osm (OpeenStreetMap) file as a reader, then used ListExploder to get the attributes for each feature as it's saved as tags, k (=key), and v (=value) , FME read these tags as a list ,..so I managed to get the columns, but I'm now stuck in how can I convert every key (or k) of the feature, into an attribute, and match to its value (v), see snapshot..

 

 

For example, k=maxspeed is an attribute and v= 100 is its value.

 

Note that every feature may have many k's, (i.e., name, lanes, oneway, maxspeed,..etc)

 

 

 

Any idea? Appreciate it..
Hi Sami,

 

 

The BulkAttributeRenamer with this setting renames "v" to value of "k" in the same row.

 

 

You can then aggregate them for each feature with the Aggregator, grouping by feature ID. If the records don't have feature ID column, consider adding unique ID for each feature with the Counter before the ListExploder.

 

And the new attribute names will not be exposed automatically. You will have to expose them with the AttributeExposer if necessary.

 

 

It's a basic solution, but if a feature may have two or more same tags (attribute names after renaming), it will be more complicated.

 

Is there such a situation? e.g. a feature may have two or more "highway" tags?

 

 

Takashi
Thanks for your reply Takashi, but unfortunately it didn't work..

 

You are correct for every uniqueID (id) value there might be several tags (to be converted to attributes names).

 

 

to better grasp the situation

 

I attached you a sample of the osm file: (https://drive.google.com/file/d/0B_VW4qFVeNpvWGQtblEzUVpEa2s/view?usp=sharing)

 

Also the workspace:

 

(https://drive.google.com/file/d/0B_VW4qFVeNpvS3pWMDJ5SXNscWs/view?usp=sharing)

 

Appreciate your help..

 

 
I think the links are not correct, try the following instead:

 

https://drive.google.com/open?id=0B_VW4qFVeNpvS3pWMDJ5SXNscWs&authuser=0

 

https://drive.google.com/open?id=0B_VW4qFVeNpvWGQtblEzUVpEa2s&authuser=0
Looks like there aren't duplicate tags for each individual feature.

 

I think the combination (BulkAttributeRenamer+Aggregator) works as expected.

 

 

Try modifying the parameters.

 

BulkAttributeRenamer

 

- Selected Attributes: v

 

- Action: Regular Expression Replace

 

- Text To Find: .+

 

- String: k   <choose the attribute "k">

 

Aggregator

 

- Group By: id

 

- Mode: Attributes Only

 

- Keep Input Attributes: Yes

 

 

And then, add an AttributeExposer to expose required attribute names (e.g. "name", "highway" etc.).

 


And it works like a charm!

 

Thanks Takashi for your help..

 

I implemented your workflow, but only modified the Aggregator parameter,(Mode:Geometry-Assemble One Level) to output the geometry of the lines.

 

 

Sami
Good to hear it worked fine :)

 

 

Regarding the "Mode" parameter of the Aggregator.

 

I think that the features (after the ListExploder) having same ID have same geometry, since the geometry of each original feature has been cloned through the ListExploder. So I'm afraid that duplicate geometries will be aggregated if you set "Geometry-Assemble One Level" to the parameter.

 

Check if the resulting geometries are properly.

 

 

If they have duplicate geometries, there are at least two ways to resolve that.

 

In both cases, set "Attributes Only" to the "Mode" parameter of the Aggregator. And optionally you can remove geometry before the ListExploder.

 

 

1. Merge the extracted attributes to original feature.

 

Add a FeatureMerger; send the original features (having geometry) to the Requestor port; send the aggregate features (having extracted attributes) to the Supplier port; join them on "id".

 

GeometryRemover -> ListExploder

 

-> BulkAttributeRenamer -> Aggregator -> AttributeExposer

 

-> >Supplier] FeatureMerger (merge the extracted attributes to original feature)

 

 

2. Extract and Restore geometry.

 

Store the geometry as an attribute by the GeometryExtractor beforehand; restore the geometry by the GeometryReplacer later.

 

GeometryExtractor -> GeometryRemover -> ListExploder

 

-> BulkAttributeRenamer -> Aggregator -> AttributeExposer

 

-> GeometryReplacer (restore the geometry)
Hi Takashi,

 

I verified the output and I confirm there are no geometry duplicates found..for curiousity, I also implemented both of the cenarios you mentioned above, and they produced the same reults and the output has no geometry duplicate as well.

 

 

Thank you.

 

Sami

Reply