According to the documentation, there is a python version of OGRGeometry's C++ class (http://www.gdal.org/ogr/classOGRGeometry.html) which is http://gdal.org/python/osgeo.ogr.Geometry-class.html

However, I don't understand why there is a lot of differences between these two class.

For instance, in Python there aren't any import method (importFromWkt).

Is it normal or maybe I'm on on the wrong way.



As gene pointed out importing from Wkt is provide under the OGR namespace and not included in the geometry module of python. Well I am saying this is not a choice by the developer who wraps the python. Python gdal is a wrapper based on SWIG. When it comes to wrapping a C++ library using SWIG there are some technical limitations and people should go other way to get the functionality. In this case "pure virtual" nature of Geometry::ImportFromWkt is the reason. So the importFomWkt is ignored by SWIG and the for keeping the functionality probably a new python function is added in the OGR namespace and ofcourse with a different name "CreateGeometryFromWkt"


For instance, in Python there aren't any import method (importFromWkt).

??? -> Look at the ogr module content:

from osgeo import ogr
print dir(ogr)
[...,  'CreateGeometryFromJson', 'CreateGeometryFromWkb', 'CreateGeometryFromWkt','CreateGeometryFromGML',...]

and the Python GDAL/OGR Cookbook 1.0 documentation:

wkt = "POINT (1120351.5712494177 741921.4223245403)"
point = ogr.CreateGeometryFromWkt(wkt)
geojson = """{"type":"Point","coordinates":[108420.33,753808.59]}"""
point = ogr.CreateGeometryFromJson(geojson)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.