span8
span4
span8
span4
sampleworkspace.zip
Question: How do I expose feature attributes from a KML
I can see the attributes within a description balloon within Google Earth.However,if I try to read the file with the KML reader or the Data Inspector,I cannot view the user attributes.
What do I need to do to load the attributes to another file type such as the shapefiles (shp)?
Answer: We need to use XQueryExtractor to get table attributes from the KML file.
1.Let's look at the source data on Google Earth.It shows a table with attributes.
Source KML viewed in Google Earth
Opening the KML file in a TextEditor,you can see that this attribute table is embedded in the tag and it is written in HTML.
2.In your FME workspace,add HTMLToXHTMLConverter to convert HTML to XHTML.This ensures that the tag contains a valid XHTML and the elements are properly nested.
HTMLToXHTMLConverter parameters
3.Add XQueryExtractor.Enter the following XQuery Expression to parse attribute names and values inside the
declare default element namespace "http://www.w3.org/1999/xhtml";for $x in /html/body/table/tr/td/table/trreturn fme:set-attribute($x/td[1]/text(),$x/td[2]/text())
If you are looking for tutorials on XQuery,please visitW3Schools.
XQueryExtractor parameters
4.Connect to the Data Inspector.
FME 亚搏在线workflow
5.View the features in Data Inspector.
Result: attributes names and attribute values are exposed in the Inspector.
6.Expose attributes.If you would like to use the attributes later in the 亚搏在线workflow or write them to your destination dataset,you will likely need to expose them.This can be accomplished by either using the AttributeExposer transformer after the XMLXQueryExtractor,or the Expose Attributes parameter within the XMLXQueryExtractor.
Thanks this is very good example!However not every *kml is so nicely structured like this.In my example the table in
something like this:
Sensor: ALOS
Mode: FBS8
Processor: JAXA
Assume that the Xquery expression need to be altered,but how?
Please find the kml attached in case my description is not clear.Would be grateful for some hints & examples to extract the attributes from this kml.Kind regards,chris.
Instead of XQueryExtractor which requires specific XQuery expression,normally for html tables you could try the XMLFlattener with feature path = 'tr' which will flatten out your description's table rows into its component fields in the form of row.column.However,I took a look at your kml and noticed that the data is not stored in an html table but rather in a large text field.So you will have to use text processing to extract the values you are after.I will follow up in your support case to explain this further.
This is a great example but for some reason it didn't work for me even though my data is structured very similarly.I found that this did work..
declare default element namespace "http://www.w3.org/1999/xhtml";for $x in //tr where (exists($x/td[1]) and compare($x/td[2]/text(),""))return fme:set-attribute($x/td[1]/text(),$x/td[2]/text())
The //tr extracts rows,regardless of what comes before,which is very handy so that you don't really need to figure out the structure.
The where(exists()) part is necessary for unknown reasons.Anything I tried without a where clause returned no results.The compare clause removed NULL parameters,which were formatted as <> in my data.I'm not sure if that is a KML standard or particular to my dataset.
I also found that I had to expose the attributes I wanted to preserve,and add them to the destination as well.This saved having to make sense of the _results field.
Hope this helps someone...
Manhole ID | 50283792 |
Life Cycle | In-Service |
Manhole Size | |
Installation Date | 1/1/1111 |
Drawing Number | MHE2-009-552 |
Grid | 4030420 |
declare default element namespace "http://www.w3.org/1999/xhtml";for $x in /html/body/table/trreturn fme:set-attribute($x/td[1]/text(),$x/td[2]/text())
Thanks for the example.
I also have a kml that is formatted differently from this example.I have tried both the XQueryExtractor and the XML Flattener but have not been able to pull out the attributes.I was wondering if someone could help me get the correct query pull out the name and the attributes from the following xml format:
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">
V18279201018990_000.jpg
Latitude:37.424416°
Longitude:-82.930091°
Roll:-15.832788°
Pitch:1.726352°
Heading:161.467052;
Height:230.000
GPS Week sec:591967.285977;0.000
Hi@justinv.
Thank you for your question.Have you tried the XMLFragmenter?
© 2019 亚搏在线Safe Software Inc |Legal