Skip to main content
I'm attempting to use the XML Reader to bring in spatial data that is stored in an XML file.  The data is in small polygons that each have a set of 5 lat/long values for each vertex of the polygon in tag called <WKT> which is a child of a parent tag called <Record>.  The <WKT> tag has several sibiling tags within the <Record> tag that are attributes with values of the polygon defined in <WKT> .  I can get the record data into an attribute table by simply entering "Record" into Elements to Match in the parameters.  However, I'm at a lost how I get the lat/long values added to the attribute table to define the polygons.  Is there something I can add to the parameters of the XML reader to do this?  Or would it take a seperate step?  I have pasted in what's in one of these <WKT> tags below.  Currently, when I only enter "Record" in Elements to Match, it puts everything within the <WKT> tage in a single column.  Secondly, it adds the Geometry as "Point" when really they should be Polygon.  Any help on this would be appreciated. 

 

 

<WKT>POLYGON((-89.326434001719164 41.151389228099951,-89.326406223907568 41.151389228099752,-89.32640622391915 41.151334328651544,-89.326434001707554 41.151334328651316,-89.326434001719164 41.151389228099951))</WKT>
Hi,

 

 

The text value of WKT element looks like an OGC Well Known Text format.

 

I think the GeometryReplacer with this setting can be used to create a polygon from the text.

 

-----

 

Geometry Encoding: OGC Well Known Text

 

Geometry Source: <attribute name containing the WKT>

 

-----

 

If the attribute value is an XML fragment (i.e. including tags <WKT> and </WKT>), remove them before the transformer.

 

 

Takashi
Thanks for the reply Takashi.  I've brand new to FME so I have no idea how to use the GeometryReplacer with the XML import.  Is it something I woudl do after I import the XML with the <WKT> info already in a table column or would it be part of the parameter during the import?  Also, I'm actually using the FME Data interoperability Extension in ArcMap, so I'm not even sure I have access to the GeometryReplacer in that extension.  Lastly, I'm not quite following you on your last sentence about the XML fragment.  How would I know if they are an XML fragment and before wha transformer.  Sorry for all the questions and thanks again for your help
According to this list, the GeometryReplacer transformer is supported by ArcGIS Interoperability Extension.

 

http://www.safe.com/solutions/for-applications/esri-arcgis/transformers/

 

 

I think it's displayed in your Transformer Gallery like this.

 

 

 

I guess that an attribute (column) of each feature which you read from the source XML stores  the WKT.

 

<WKT>POLYGON(...)</WKT>

 

or

 

POLYGON (...)

 

 

XML fragment I mentioned means the first text above. i.e. the body of WKT is surrounded by <WKT> and </WKT>. If the attribute value is an XML fragment, change it to the second format (remove <WKT> and </WKT>) before sending feature to the GeometryReplacer.

 

To see the actual attribute values, consider using the Inspector and / or Logger transformer. If you connect one or both of them to the reader, you can then inspect attribute values read from the source XML.
# correction for typos.

 

P.S. if there are multiple <WKT> elements under a <Record> element, WKT texts might be stored as a list attribute (e.g. WKT{0}, WKT{1} ...). If so, you will have to convert the list attribute into individual elements (non-list attributes). You can use the ListExploder transformer to do that.

 

Anyway, the Inspector and the Logger will help you always, anywhere.
Thanks again Takashi.  I kind of have it working with your help but now I'm stuck on how I can get the features into ArcMap.  I added an Inspector and after the features were created based on the WKT data, it opens the data in the inspector where I visually see the data.  However, now I don't know how I can get into a format that will  show in ArcMap.  Is there a way to get these features into a shp file or geodatabase?  
The resultant features can be written into any format dataset using an appropriate writer. Try adding a shp or geodatabase writer to the workspace (Workbench menu: Writers > Add Writers).

 

Since I've never used ArcGIS Interoperability Extension, I'm not sure whether there is a specific way to add saved shp or geodatabase to ArcMap automatically. At least, I think you can add the layer to the map manually, after writing shp or geodatabase with the workspace.
Takashi.  I wasn't able to add a Writer initially but started over and then it allowed me.  So I've got them in Arcmap now.  Now I need to figure out how to include the sibling tags to the record so I can include those at attribute values of each feature.  I imagine there is some way to do that.  
If there are multiple <WKT> elements under a <Record> element, I think the XML reader feature type is showing "WKT{}" as attribute name. "WKT{}" is a list attribute which stores every sibling under the Record.

 

List attribute has to be converted to individual elements (non-list attributes) before creating geometries. You can use the ListExploder to do that.

 

http://docs.safe.com/fme/html/FME_Transformers/Default.htm#Transformers/listexploder.htm

 


There are not multiple <WKT> elements, only 1 per <Record> elements.  The <Record> represents each feature.  Then these features are a child of a <Records> element.  Then there are sibling elements that are more header information.  So it probably doesn't make sense to replicate this header info into each feature.  Possibly just need to store these sibling elements in a joined table.  
If the XML document is like this, for example, "Sibling1" and "Sibling2" will be attribute names of the Record feature, and a feature will store "Value1" and "Value2" as attribute values associated to the names.

 

-----

 

<?xml version="1.0"?>

 

<root>

 

    <Record>

 

        <WKT>POLYGON(...)</WKT>

 

        <Sibling1>Value1</Sibling1>

 

        <Sibling2>Value2</Sibling2>

 

        ...

 

    </Record>

 

    ...

 

</root>

 

-----

 

 

To write those attribute values into the destination dataset, you will have to edit "User Attributes" of the writer feature type. See here to learn more about editing writer feature type properties.

 

http://docs.safe.com/fme/html/FME_Workbench/Default.htm#editing_writer_feature_type_properties.htm

 


Reply