Skip to main content
Hi all,

 

 

I have a GML geometry that I would like to convert to WKT (in order to insert it in the geometry with Z column of a PostGIS DB). Here is a geometry sample (from CityGML):

 

  
 <gml:MultiSurface srsName="EPSG:4979" srsDimension="3">                     <gml:surfaceMember srsDimension="3">                         <gml:Polygon srsDimension="3">                             <gml:exterior>                                 <gml:LinearRing srsDimension="3">                                     <gml:posList srsDimension="3">41.8636830995329 12.4911723999943 0 41.8637580995329 12.4912074999943 0 41.8637078995329 12.4914008999944 0 41.8636328995329 12.4913657999944 0 41.8636830995329 12.4911723999943 0</gml:posList>                                 </gml:LinearRing>                             </gml:exterior>                         </gml:Polygon>                     </gml:surfaceMember>                     <gml:surfaceMember srsDimension="3">                         <gml:Polygon srsDimension="3">                             <gml:exterior>                                 <gml:LinearRing srsDimension="3">                                     <gml:posList srsDimension="3">41.8637580995329 12.4912074999943 0 41.8636830995329 12.4911723999943 0 41.8636830995329 12.4911723999943 13 41.8637580995329 12.4912074999943 13 41.8637580995329 12.4912074999943 0</gml:posList>                                 </gml:LinearRing>                             </gml:exterior>                         </gml:Polygon>                     </gml:surfaceMember>                     <gml:surfaceMember srsDimension="3">                         <gml:Polygon srsDimension="3">                             <gml:exterior>                                 <gml:LinearRing srsDimension="3">                                     <gml:posList srsDimension="3">41.8637078995329 12.4914008999944 0 41.8637580995329 12.4912074999943 0 41.8637580995329 12.4912074999943 13 41.8637078995329 12.4914008999944 13 41.8637078995329 12.4914008999944 0</gml:posList>                                 </gml:LinearRing>                             </gml:exterior>                         </gml:Polygon>                     </gml:surfaceMember>           P...]           </gml:MultiSurface>
 So, the <gml:MultiSurface> contains several <gml:surfaceMember>, each of them being a <gml:Polygon>. I would like to convert this geometry to a WKT Multipolygon representation. If I use a GeometryExtractor, my input GML geometry is output like this and cannot be inserted into the PostGIS table:

 

  
 MULTIPOLYGON ((12.4889684999943 41.8608646995328 0,12.4892365999943 41.8608671995328 0),(12.4892365999943 41.8608671995328 0,12.4892352999943 41.8608493995329 0),(12.4892352999943 41.8608493995329 0,12.4893177999943 41.8608503995328 0),(12.4893177999943 41.8608503995328 0,12.4893234999943 41.8606906995328 0),(12.4893234999943 41.8606906995328 0,12.4889687999943 41.8606866995328 0),(12.4889687999943 41.8606866995328 0,12.4889684999943 41.8608646995328 0)),MULTIPOLYGON ((12.4892365999943 41.8608671995328 0,12.4889684999943 41.8608646995328 0),(12.4889684999943 41.8608646995328 0,12.4889684999943 41.8608646995328 9),(12.4889684999943 41.8608646995328 9,12.4892365999943 41.8608671995328 9),(12.4892365999943 41.8608671995328 9,12.4892365999943 41.8608671995328 0)),MULTIPOLYGON ((12.4892352999943 41.8608493995329 0,12.4892365999943 41.8608671995328 0),(12.4892365999943 41.8608671995328 0,12.4892365999943 41.8608671995328 9),(12.4892365999943 41.8608671995328 9,12.4892352999943 41.8608493995329 9),(12.4892352999943 41.8608493995329 9,12.4892352999943 41.8608493995329 0)),MULTIPOLYGON ((12.4893177999943 41.8608503995328 0,12.4892352999943 41.8608493995329 0),(12.4892352999943 41.8608493995329 0,12.4892352999943 41.8608493995329 9),(12.4892352999943 41.8608493995329 9,12.4893177999943 41.8608503995328 9),(12.4893177999943 41.8608503995328 9,12.4893177999943 41.8608503995328 0)),MULTIPOLYGON ((12.4893234999943 41.8606906995328 0,12.4893177999943 41.8608503995328 0),(12.4893177999943 41.8608503995328 0,12.4893177999943 41.8608503995328 9),(12.4893177999943 41.8608503995328 9,12.4893234999943 41.8606906995328 9),(12.4893234999943 41.8606906995328 9,12.4893234999943 41.8606906995328 0)),MULTIPOLYGON ((12.4889687999943 41.8606866995328 0,12.4893234999943 41.8606906995328 0),(12.4893234999943 41.8606906995328 0,12.4893234999943 41.8606906995328 9),(12.4893234999943 41.8606906995328 9,12.4889687999943 41.8606866995328 9),(12.4889687999943 41.8606866995328 9,12.4889687999943 41.8606866995328 0)),MULTIPOLYGON ((12.4889684999943 41.8608646995328 0,12.4889687999943 41.8606866995328 0),(12.4889687999943 41.8606866995328 0,12.4889687999943 41.8606866995328 9),(12.4889687999943 41.8606866995328 9,12.4889684999943 41.8608646995328 9),(12.4889684999943 41.8608646995328 9,12.4889684999943 41.8608646995328 0)),MULTIPOLYGON ((12.4889684999943 41.8608646995328 9,12.4889687999943 41.8606866995328 9),(12.4889687999943 41.8606866995328 9,12.4893234999943 41.8606906995328 9),(12.4893234999943 41.8606906995328 9,12.4893177999943 41.8608503995328 9),(12.4893177999943 41.8608503995328 9,12.4892352999943 41.8608493995329 9),(12.4892352999943 41.8608493995329 9,12.4892365999943 41.8608671995328 9),(12.4892365999943 41.8608671995328 9,12.4889684999943 41.8608646995328 9))
 Any idea what I am doing wrong?

 

 

Best regards

 

 

 
Hi,

 

 

I think the GeometryExtractor (OGC Version: 1.2) can create a WKT with Z which is valid for PostGIS.

 

BTW, the PostGIS writer can write the geometry data into a geometry column directly. Usually you don't need to extract WKT from geometries if you use the writer. How are you going to write the geometry? SQL?

 

 

Takashi
Hi Takashi,

 

 

Thaks for your answer. You are right, FME PostGIS writer xan write the geometry data in the right column (when set). However, it creates the geometry as a GEOMETRYCOLLECTION Z (POLYHEDRALSURFACE Z(...)). I need the geometry to be a MULTIPOLYGON with Z ccordinates. Any idea?

 

 

Regards,

 

 

Asherk
How about using the SQLExecutor to insert the features into the PostGIS table?

 

-----

 

insert into <table name> (<geometry column name>, <other column>, ...)

 

values (ST_GeometryFromText('<WKT>', <SRID>), <other value>, ...)

 

-----

 

or

 

-----

 

insert into <table name> (<geometry column name>, <other column>, ...)

 

values (ST_GeomFromEWKT('SRID=<SRID>;<WKT>'), <other value>, ...)

 

-----
Takashi,

 

Seems a good idea. However, how can I get the geometry as a WKT string? i.e. how to build a MULTIPOLYGON from my original GML geometry?

 

 

Regards,

 

 

Asher
Once create a geometry from the GML with the GeometryReplacer, and then extract WKT from the geometry with the GeometryExtractor. The GeometryExtractor (Geometry Encoding: OGC Well Known Text, OGC Version: 1.2) extracts "MULTIPOLYGON Z" representation, which can be passed to <WKT> in the SQL statement.
Takashi,

 

 

If I use the GeometryExtractor transformer on my GML geometry, it is outputed in WKT 1.2 as:

 

  
 GEOMETRYCOLLECTION Z (MULTILINESTRING Z ((...)) MULTILINESTRING Z ((...)) ...)
 

 

and not as would like: 
 MULTIPOLYGONZ( ......)
 

 

I am sirry, but I cannot understand how can I achieve this?

 

 

Regards
In my quick test, the GeoemetryReplacer/Extractor created "MULTIPOLYGON Z(...)" from the GML fragment that you posted first.

 

 

 

The GeometryReplacer created a 3D MultiArea containing 3 parts, and the GeometryExtractor extracted "MULTIPOLYGON Z" from the geometry. Check your result with FME Data Inspector, like this. 

 


If the geometry was a heterogeneous aggregate (i.e. containing various type geometries such as polygon, line etc.), the GeometryExtractor extracts "GEOMETRYCOLLECTION Z".
Hi Takashi,

 

 

My geometry is read from a citygml file. I thus use the CityGML reader and do not understand how I can use the GeometryReplacer that you are using. If you are interested, I can share a template workspace with some data.

 

 

Best regards,

 

 

Olivier
If possible, upload the template to a shareable location such as Google Drive, paste the URL here. 
Takashi,

 

 

FMWT: https://drive.google.com/open?id=0B-_OfMv1gWRibG94QVpfcHJyZ1U

 

CityGML file: https://drive.google.com/open?id=0B-_OfMv1gWRiZ0xHMmhMVmFYVUk

 

 

Best regards
The files are limited access. I requested access through Google system, please confirm your mail box.
Done
The CityGML reader creates multi-surface (IFMEMutliSurface) geometries from GML MultiSurface elements. The GeometryExtracotr will not extract "MULTIPOLYGON Z" from multi-surface. You will have to get multi-polygon (IFMEMultiArea) geometries.

 

 

A possible way is:

 

Extract polygon geometries from the multi-surfaces with the GeometryPartExtractor.

 

Geometry XQuery example.

 

- Part to Test: The parent of this part

 

- Left Value: Geometry Type

 

- Operator: =

 

- Right Value: IFMEFace

 

 

The transformer extracts the child geometries for every IFMEFace. Each resulting feature will have a single-part polygon geometry (IFMEPolygon).

 

After this, use the Aggregator to construct multi-polygon (IFMEMultiArea).

 

Group By: gml_id

 

Mode: Geometry - Assemble One Level

 

Keep Input Attributes: Yes (if you need to keep attributes)

 

Aggregate Type: Homogeneous (If Possible)

 

 

You can then extract "MULTIPOLYGON Z" from the multi-polygon with the GeometryExtractor.

 

 

However, probably you can write the multi-polygon geometries into the PostGIS database with the PostGIS writer directly, without extracting WKT.

Reply