Is .shp file, without the dbf, .shx, .prj
or others, enough to get the bounding box?
I am trying to get user to upload their shapefiles in a web page. I want to obtain longitude and latitude from the point shapefile, and bounding box (long,lat long,lat) from the polygon shapefile (both the shapefile will contain single shape/feature). I would like to think .shp
file is enough to obtain the shape, but when I use fiona
, it gives me an error. Is there any package that might help?
The code looks like this:
import fiona
from shapely.geometry import shape
shp_file = 'a_polygon_shapefile.shp'
c = fiona.open(shp_file)
# first record
first_shape = c.next()
box_topY = shape(first_shape['geometry']).bounds[3]
box_bottomY = shape(first_shape['geometry']).bounds[1]
box_rightX = shape(first_shape['geometry']).bounds[2]
box_leftX = shape(first_shape['geometry']).bounds[0]
The error I get is:
Unable to open a_polygon_shapefile.shx or a_polygon_shapefile.SHX.Try --config SHAPE_RESTORE_SHX true to restore or create it
ogrinfo bounds.shp --config SHAPE_RESTORE_SHX TRUE -al -so INFO: Open of
bounds.shp' using driverESRI Shapefile' successful. Layer name: bounds Geometry: Polygon Feature Count: 1 Extent: (500.000000, 280.000000) - (740.000000, 480.000000) Layer SRS WKT: (unknown)
WGS 1984
only to avoid the ambiguity.