[gdal-dev] How to set BoundingBox within a shapefile using OGR
Pythons bindings
Even Rouault
even.rouault at mines-paris.org
Wed Dec 16 13:40:36 EST 2009
Daniele,
Try: ogr.CreateGeometryFromWkt(wkt)
Best regards,
Even
Daniele Romagnoli a écrit :
> Hi list,
> I'm creating a shapefile using the OGR python bindings. (from the
> 1.6.1 installer)
> I have some issues in creating the boundingBox for it.
> This is a snippet of the code I'm using:
> -----------------------------------------------------
> from osgeo import ogr
> from osgeo import osr
> ....
> ....
> northings_llc = dd['northings_llc']
> northings_urc = dd['northings_urc']
> eastings_llc = dd['eastings_llc']
> eastings_urc = dd['eastings_urc']
> t_srs = osr.SpatialReference()
> t_srs.SetFromUserInput('EPSG:32632')
> drv = ogr.GetDriverByName('ESRI Shapefile')
> ds = drv.CreateDataSource(fileout)
> x0, y0, x1, y1 = str(eastings_llc[0][0]), str(northings_llc[0][0]),
> str(eastings_urc[0][0]), str(northings_urc[0][0])
>
> layer = ds.CreateLayer(ds.GetName(), geom_type = ogr.wkbPolygon, srs =
> t_srs)
> geom = ogr.Geometry(type = layer.GetLayerDefn().GetGeomType())
> geom.AssignSpatialReference(t_srs)
> wkt = 'POLYGON('+x0+','+y0+','+ x0+','+ y1+','+ x1+',' +y1+','+ x1+','
> +y0+','+ x0+',' +y0+')'
> print(wkt)
> geom.importFromWkt(wkt)
> ...
> ...
>
> When running, I get this output:
> POLYGON(602759.984846,4739727.96408,602759.984846,4739720.3473,602760.45247,4739720.3473,602760.45247,4739727.96408,602759.984846,4739727.96408)
> Traceback (most recent call last):
> File "prova.py", line 42, in <module>
> geom.importFromWkt(wkt)
> File "c:\python26\lib\site-packages\osgeo\ogr.py", line 2672, in
> <lambda>
> __getattr__ = lambda self, name: _swig_getattr(self, Geometry, name)
> File "c:\python26\lib\site-packages\osgeo\ogr.py", line 34, in
> _swig_getattr
> raise AttributeError,name
> AttributeError: importFromWkt
>
> Indeed, looking at the ogr.py there is no "importFromWkt" in the
> Geometry definition.
> How can I set the bounding box within the geometry?
> Any help would be greatly appreciated.
>
> Best Regards,
> Daniele
>
> --
> -------------------------------------------------------
> Eng. Daniele Romagnoli
> Software Engineer
>
> GeoSolutions S.A.S.
> Via Carignoni 51
> 55041 Camaiore (LU)
> Italy
>
> phone: +39 0584983027
> fax: +39 0584983027
> mob: +39 328 0559267
>
>
> http://www.geo-solutions.it
>
> -------------------------------------------------------
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
More information about the gdal-dev
mailing list