Skip to main content
Solved

Extracting geometry from SQL Reader

  • March 8, 2021
  • 5 replies
  • 176 views

Forum|alt.badge.img

I have an SQL reader the loads json and a geometry from a postgis table

SELECT $SQL$@Value(schema)$SQL$ AS schema,
       attributes,
       wkb_geometry
FROM @Value(schema).features_addresses

I have to do this as the database connection is dynamic as is the schema and cannot be fixed in a Reader. 

 

My question is how do I extract the geometry as an FME geometry so it can be passed to a FeatureWriter?

 

I tried using a GeometryReplacer and WKB format but FME rejects the WKB even though it is valid?

 

Screenshot 2021-03-08 at 16.30.25

Best answer by david_r

 SELECT '0101000020E61000000C3C69A7CF178E3FF54274395CBF4940'::GEOMETRY works fine. 

 

Postgis stores geometries natively as wkb 

I agree with @ebygomm​ , I also suspect that it's the datatype. If you look at the ST_AsEWKB() function in PostGIS, it returns a bytea column, not a geometry or varchar-style column. If you do the same thing it should work in FME.

Suggestion:

SELECT $SQL$@Value(schema)$SQL$ AS schema,
           attributes,
           ST_AsEWKB(wkb_geometry) as wkb_geometry
    FROM @Value(schema).features_addresses

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

david_r
Celebrity
  • 8392 replies
  • March 8, 2021

I use that technique all the time and I've never had any problems with it. How do you know that the WKB is valid? What datatype is the column "wkb_geometry"?


Forum|alt.badge.img
  • Author
  • 14 replies
  • March 8, 2021

 SELECT '0101000020E61000000C3C69A7CF178E3FF54274395CBF4940'::GEOMETRY works fine.

 

Postgis stores geometries natively as wkb


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • March 8, 2021

I think the issue is the datatype of the column, try putting a BinaryDecoder in to get the attribute containing the geometry to be encoded as fme-binary before sending it into the GeometryReplacer

Capture 

 


david_r
Celebrity
  • 8392 replies
  • Best Answer
  • March 9, 2021

 SELECT '0101000020E61000000C3C69A7CF178E3FF54274395CBF4940'::GEOMETRY works fine. 

 

Postgis stores geometries natively as wkb 

I agree with @ebygomm​ , I also suspect that it's the datatype. If you look at the ST_AsEWKB() function in PostGIS, it returns a bytea column, not a geometry or varchar-style column. If you do the same thing it should work in FME.

Suggestion:

SELECT $SQL$@Value(schema)$SQL$ AS schema,
           attributes,
           ST_AsEWKB(wkb_geometry) as wkb_geometry
    FROM @Value(schema).features_addresses

 


Forum|alt.badge.img
  • Author
  • 14 replies
  • March 9, 2021

Thanks for the help.. I fixed it with a CAST in the SQL

 

SELECT $SQL$@Value(schema)$SQL$ AS schema,
       attributes,
       ST_ASEWKB(wkb_geometry) AS wkb_geometry
FROM @Value(schema).features_addresses