4

I have a shapefile where I am exporting the features to GeoJSON objects with ogr2ogr based on a simple where clause. One thing that I would like to be included in the GeoJSON object is the 'bbox' member (outlined here) , is it possible to add this as an attribute to the shapefile using QGIS?

I've done something similar with centroids and added the x/y as separate attributes. Are there any other ways to programmatically add this to my geojson files?

  • I've managed to solve my bounding box problem elsewhere, but I'd still love to know if it is possible to do this with QGIS! – Kevin Mar 2 '12 at 19:23
  • 1
    It might be easier if you post the solution you figured out elsewhere and see if someone can adapt that solution to QGIS. – Get Spatial May 26 '12 at 9:39
5

With ogr2ogr you can use -lco WRITE_BBOX=YES to output bounding box.

0

@spatialthoughts is right and another way is that make your geojsons to GDAL Virtual Format and then add your bounding box to in tags.

with gdalinfo you can get info about your vrt file. a nice addition to vrt is that it has ability to directly import into QGIS.

you can get some code in here about manually adding bbox here.

            geotransform = [0.0,0.0,0.0,0.0,0.0,0.0]

            geotransform[0] = bbox[3]
            geotransform[1] = (bbox[2] - bbox[3]) / float(xsize)
            geotransform[2] = 0.0
            geotransform[3] = bbox[0]
            geotransform[4] = 0.0
            geotransform[5] = (bbox[1] - bbox[0]) / float(ysize)

            in_ds.SetGeoTransform(geotransform)

i hope it helps you...

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.