Opened 11 years ago
Closed 11 years ago
#5236 closed defect (invalid)
hape geometries
Reported by: | aiur | Owned by: | Even Rouault |
---|---|---|---|
Priority: | highest | Milestone: | |
Component: | JavaBindings | Version: | 1.10.0 |
Severity: | trivial | Keywords: | shapefile extent |
Cc: |
Description (last modified by )
I'm running a short Python script to offset and scale the geometry in a line shapefile. The geometry features move as planned, but the extent of the shapefile doesn't update as expected according the ogrinfo. The max xy are changed, but the min xy remain unchanged. Below I've pasted the Python script followed by the ogrinfo output. Do I need to add something to the Python script to get the extents refreshed?( I think this information is the shx file).
JavaBinding v1.10.0 has this problem too.
JavaBinding v1.10.0 has this problem too.
code:
#mine_to_utm.py import ogr #include the .shp extension #sShpName = "section_lines_test_ln.shp" sShpName = "test_utm_lnz.shp" dXOffset = 1711586.62 dYOffset = 14712509.9 dScale = 0.3048 ogrdriver = ogr.GetDriverByName("ESRI Shapefile") ogrSDS = ogrdriver.Open(sShpName, 1) mLayer = ogrSDS.GetLayerByName(sShpName[:-4]) for i in range(mLayer.GetFeatureCount()): mFeature = mLayer.GetFeature(i) mGeom = mFeature.GetGeometryRef() #only process simple LINESTRING if (mGeom.GetGeometryCount() == 0): #create new wkt geometry sWkt = "LINESTRING (" for j in range(mGeom.GetPointCount()): dX = mGeom.GetX(j) dY = mGeom.GetY(j) dZ = mGeom.GetZ(j) dXNew = (dX + dXOffset) * dScale dYNew = (dY + dYOffset) * dScale sWkt += str(dXNew) + " " + str(dYNew) + " " + str(dZ) + "," sWkt = sWkt[:-1] + ")" newGeom = ogr.CreateGeometryFromWkt(sWkt) mFeature.SetGeometryDirectly(newGeom) mLayer.SetFeature(mFeature) else: print "Geometry not supported." print mGeom break ogrSDS.Destroy()
S:\>ogrinfo -al test_utm_lnz.shp
INFO: Open of `test_utm_lnz.shp' using driver `ESRI Shapefile' successful. Layer name: test_utm_lnz Geometry: 3D Line String Feature Count: 2 Extent: (25197.816780, 14676.458434) - (30479.027175, 30724.795652) ↑↑↑↑ Layer SRS WKT: (unknown) FID_: Integer (9.0) OGRFeature(test_utm_lnz):0 FID_ (Integer) = (null) LINESTRING (30409.466042881133 30667.436514034867 0,25433.42988651176 30724.79 5651653782 0) OGRFeature(test_utm_lnz):1 FID_ (Integer) = (null) LINESTRING (30479.027175426483 14678.760769195855 0,25197.816779945977 14676.4 58433972672 0)
S:\>mine_to_utm.py S:\>ogrinfo -al test_utm_lnz.shp
INFO: Open of `test_utm_lnz.shp' using driver `ESRI Shapefile' successful. Layer name: test_utm_lnz Geometry: 3D Line String Feature Count: 2 Extent: (25197.816780, 14676.458434) - (530981.609259, 4493737.935230) ↑↑↑↑ Layer SRS WKT: (unknown) FID_: Integer (9.0) OGRFeature(test_utm_lnz):0 FID_ (Integer) = (null) LINESTRING (530960.40702599997 4493720.4521700004 0,529443.71120500006 4493737 .9352299999 0) OGRFeature(test_utm_lnz):1 FID_ (Integer) = (null) LINESTRING (530981.60925900005 4488847.1037999997 0,529371.89633100003 4488846.4020499997 0)
Change History (5)
comment:1 by , 11 years ago
Description: | modified (diff) |
---|
follow-ups: 3 4 comment:2 by , 11 years ago
comment:3 by , 11 years ago
Replying to jratike80:
Hi,
I believe you should read the section "Spatial extent" in http://www.gdal.org/ogr/drv_shapefile.html and try to "invoke the SQL 'RECOMPUTE EXTENT ON <tablename>' via the datasource ExecuteSQL() method". I have no idea about how you can do it with your python code.
Hi, Thank you so much. but how can i find tablename in shapefile ?
comment:4 by , 11 years ago
Replying to jratike80:
Hi,
I believe you should read the section "Spatial extent" in http://www.gdal.org/ogr/drv_shapefile.html and try to "invoke the SQL 'RECOMPUTE EXTENT ON <tablename>' via the datasource ExecuteSQL() method". I have no idea about how you can do it with your python code.
I got it, Thank you so so so much.
comment:5 by , 11 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Summary: | shapefile extent not updated after changing shape geometries → hape geometries |
Hi,
I believe you should read the section "Spatial extent" in http://www.gdal.org/ogr/drv_shapefile.html and try to "invoke the SQL 'RECOMPUTE EXTENT ON <tablename>' via the datasource ExecuteSQL() method". I have no idea about how you can do it with your python code.