Skip to main content
Open

Add the "EWKT" Geometry Encoding to GeometryReplacer

Related products:Transformers
  • March 23, 2022
  • 1 reply
  • 44 views

oliviergayte
Contributor
Forum|alt.badge.img

Add the "EWKT" Geometry Encoding definition to GeometryReplacer and GeometryExtractor.

EWKT is a simple extension to WKT that allows to include the coordinate system with the geometry, for instance: "SRID=4326;POINT(-44.3 60.1)" instead of "POINT(-44.3 60.1)"

https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry

EWKT is supported by Postgis and can be found in many open datasets.

1 reply

verdoodtdries
Enthusiast
Forum|alt.badge.img+23

​@oliviergayte , you can use this in a PythonCaller to convert ewkt string into a geometry.

import fme
from fme import BaseTransformer
import fmeobjects


class FeatureProcessor(BaseTransformer):
def __init__(self):
self.log = fmeobjects.FMELogFile()

def log2FME(self, message, severity=fmeobjects.FME_INFORM):
"""
Sends message to the FME log file and console window.
Severity must be one of FME_INFORM, FME_WARN, FME_ERROR,
FME_FATAL, FME_STATISTIC, or FME_STATUSREPORT.
"""
self.log.logMessageString(message, severity)

def setEWKT(self, f: fmeobjects.FMEFeature, ewkt: str) -> fmeobjects.FMEFeature:
"""
Overwrites the geometry and coordinate system based on an extended WKT.

param f: feature
type f: fmeobjects.FMEFeature
param ewkt: attribute name of the ewkt string
type: ewkt: str
"""
geometry = f.getAttribute(ewkt)
srid, ogcwkt = geometry.split(';')
epsg = srid.replace('SRID=', 'EPSG:')

f.importGeometryFromOGCWKT(ogcwkt)
f.setCoordSys(epsg)

return f


def getEWKT(self, f: fmeobjects.FMEFeature, ewkt: str) -> fmeobjects.FMEFeature:
"""
Extract ewkt geometry from a feature and set it to an attribute

param f: feature
type f: fmeobjects.FMEFeature
param ewkt: attribute name of the ewkt string
type: ewkt: str
"""
wkt_geometry = f.exportGeometryToOGCWKT(1)
epsg = f.getCoordSys()
srid = epsg.replace('EPSG:', 'SRID=')

ewkt_geometry = '{0};{1}'.format(srid, wkt_geometry)

f.setAttribute(ewkt, ewkt_geometry)

return f

def input(self, feature: fmeobjects.FMEFeature):
feature = self.setEWKT(f=feature, ewkt='geometry')

self.pyoutput(feature, output_tag="PYOUTPUT")

def close(self):
pass