[Qgis-developer] QgsGeometry.fromWkt fails if WKT contains SRID

Matthias Kuhn matthias.kuhn at gmx.ch
Fri Dec 21 10:06:22 PST 2012


Investigating the problem a bit reveals that including an SRID in the 
WKT is actually EWKT, a postgis format [0].

I think QgsGeometry does not support this so far (at least there is no 
occurence of EWKT in qgsgeometry.cpp)?

I see two solutions: change the postgres provider to read WKT instead of 
EWKT for subsequent geometry columns, or teach QgsGeometry to understand 
EWKT (preferred IMHO).

Any opinions on this?

Regards,
Matthias

[0]: http://en.wikipedia.org/wiki/Well-known_text
/EWKT/and/EWKB/–/Extended Well-Known Text/Binary/– APostGIS 
<http://en.wikipedia.org/wiki/PostGIS>-specific format that includes 
thespatial reference system identifier 
<http://en.wikipedia.org/wiki/Spatial_reference_system_identifier>(SRID).^[2] 
<http://en.wikipedia.org/wiki/Well-known_text#cite_note-2> For 
example:|SRID=4326;POINT(-44.3 60.1)|to locate a longitude/latitude 
coordinate using theWGS 84 
<http://en.wikipedia.org/wiki/World_Geodetic_System>reference coordinate 
system.




On 12/21/2012 05:12 PM, Matthias Kuhn wrote:
> On 12/21/2012 05:10 PM, Matthias Kuhn wrote:
>> Hi,
>>
>> I want to get a QgsGeometry from the following string, produced by 
>> PostGIS:
>>
>> /SRID=21781;LINESTRING(749566.243 264032.415,749589.521 264042.261)//
>> /
>> /QgsGeometry.fromWkt/ returns NULL, because /GEOSWKTReader_read/ 
>> throws an exception
>> (ParseException: Unknown type: 'SRID=21781;POLYGON')
> I mixed up the geometry and error message (Polygon and LineString). It 
> failed with both.
>>
>> What is the proper way to handle this:
>> - Open an issue upstream to fix it at GEOS level?
>> - Strip the SRID part from the WKT before calling GEOSWKTReader_read?
>> - Anything else?
>>
>> Regards,
>> Matthias
>> _______________________________________________
>> Qgis-developer mailing list
>> Qgis-developer at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer



More information about the Qgis-developer mailing list