Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
    
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

2 Answers 2

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

share|improve this answer

@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...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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