Skip to main content
Question

How can I turn an attribute (bunch of coordinates) into an object (polygon)?


Hey folks,

 

I'm in a bit of a trouble. The readout of an xml file gives me an attribute that contains coordinates.

 

The attribute's content is like this:

'47.609703,9.858943 47.620427,9.867245 47.613033,9.92076 47.600331,9.930115 47.612142,9.960663 47.61008,9.972698 47.631773,9.980192 47.609703,9.858943 47.609703,9.858943'

Please be aware that i shortend the count of numbers.

All I am trying is to build a polygon with these coordinates to write an Esri shapefile.

The PolygonBuilder/AreaBuilder won't help because it needs polylines to work with.

 

Thanks you so much,

Ed

4 replies

erik_jan
Contributor
Forum|alt.badge.img+18
  • Contributor
  • November 6, 2017

The GeometryReplacer can do this for you after you format the string to match a WKT.


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • November 6, 2017

If you rebuild the GML you can use a geometryReplacer

 

 

<gml:Polygon>   <gml:exterior>     <gml:LinearRing>       <gml:coordinates>@Value(_coord)</gml:coordinates>     </gml:LinearRing>   </gml:exterior> </gml:Polygon>

mark2atsafe
Safer
Forum|alt.badge.img+44
  • Safer
  • November 6, 2017

I'd first try one of the GeometryReplacer suggestions, or just use the GML reader, which I think might pull geometry out of any XML file.

The long way around would be to use an AttributeSplitter to split the attribute at each space character, a ListExploder, SubstringExtractors (to get out each x/y), and a VertexCreator to turn those values into points. Then a PointConnector.

But there shouldn't be a need to self-parse XML like that. I feel sure you'll be able to handle the content directly in a much easier way.


erik_jan
Contributor
Forum|alt.badge.img+18
  • Contributor
  • November 6, 2017
erik_jan wrote:

The GeometryReplacer can do this for you after you format the string to match a WKT.

Syntax of WKT for polygon:

 

POLYGON ((@Value(_coords)))

 

will result in:

 

POLYGON ((47.609703,9.858943 47.620427,9.867245 47.613033,9.92076 47.600331,9.930115 47.612142,9.960663 47.61008,9.972698 47.631773,9.980192 47.609703,9.858943 47.609703,9.858943)))

 

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings