unfortunately I could make this work but it's very awkward... there is something esri does different when encoding wkt geometries that postgis just finds invalid... namely, using 1.#QNAN000 when a z or m coordinate is undefined. In the mean time, I found I had been trying this already <a href="http://postgis.refractions.net/pipermail/postgis-devel/2008-August/003433.html" target="_top" rel="nofollow" link="external">back in 2008</a>!! Time flies...
<br/>
1) convert from esri to text (zm geometries)
<br/><code>select sde.st_astext(shape) from gdbman.srega_adutores limit 1;</code>
<br/>
<br/><code>LINESTRING ZM ( 36227.79210000 -170369.11470000 0.00000000 1.#QNAN000, 36211.96660000 -170348.55650000 0.00000000 1.#QNAN000, 36201.84180000 -170334.21600000 0.00000000 1.#QNAN000, 36192.28410000 -170319.49250000 0.00000000 1.#QNAN000, 36183.30730000 -170304.40710000 0.00000000 1.#QNAN000, 36174.92650000 -170288.98260000 0.00000000 1.#QNAN000, 36167.15260000 -170273.24310000 0.00000000 1.#QNAN000)</code>
<br/>
<br/>2) I can remove ZM from this string with regexp_replace:
<br/><code>select regexp_replace(cast(sde.st_astext(shape) as text), ' Z| M| ZM','') from gdbman.srega_adutores limit 1;</code>
<br/>
<br/><code>LINESTRING ( 36227.79210000 -170369.11470000 0.00000000 1.#QNAN000,...</code>
<br/>
<br/>3) When converting this string to pg_geometry pg says it's invalid:
<br/><code>select geomfromtext(regexp_replace(cast(sde.st_astext(shape) as text), ' Z| M| ZM','')) from gdbman.srega_adutores limit 1;</code>
<br/>
<br/><code>ERROR:  parse error - invalid geometry<br/>
HINT:  "...210000 -170369.11470000 0.00000000 1." <-- parse error at position 58 within geometry</code>
<br/>
<br/>It seems #QNAN000 is invalid (this is a undefined value in esri's world). I can replace it with a ad-hoc value to signal undefined coordinates (eg -99999), with a new regexp_replace:
<br/>
<br/>3) remove #qnan000
<br/><code>select regexp_replace(regexp_replace(cast(sde.st_astext(shape) as text), ' Z| M| ZM',''),'1.#QNAN000','-99999','g') from gdbman.srega_adutores limit 1;</code>
<br/>
<br/><code>LINESTRING ( 36227.79210000 -170369.11470000 0.00000000 -99999,...</code>
<br/>
<br/>This finally works well with postgis:
<br/>
<br/>4) create a postgis geometry
<br/><code>select geomfromtext(regexp_replace(regexp_replace(cast(sde.st_astext(shape) as text), ' Z| M| ZM',''),'1.#QNAN000','-99999','g')) from gdbman.srega_adutores limit 1;</code>
<br/>
<br/>whew...
<br/>
<br/>Is it worth it?
<br/>
<br/>I ended up using esri's tools to copy from esri_st to pg_geometry by selecting the appropriate sde keywords...
        
<br/><hr align="left" width="300" />
View this message in context: <a href="http://postgis.17.n6.nabble.com/z-m-zm-geometries-tp4981255p4997633.html">Re: z,m,zm geometries</a><br/>
Sent from the <a href="http://postgis.17.n6.nabble.com/PostGIS-User-f3516033.html">PostGIS - User mailing list archive</a> at Nabble.com.<br/>