Geotaxonomy- building bounding box from esri shapefile

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
sbauch's picture

Im looking to import geo taxonomy terms with bounding boxes, but am starting from an esri shapefile I got from nyc.gov. Should I look elsewhere for a geodatabase with bounding box values already? Or is there an opensource way to build best-fit bounding boxes from a shapefile? I found an ArcGIS script that does this, but don't own or want to purchase ArcGIS.

Any ideas? Keep in mind I'm essentially a point and click user.

Comments

Here's a really basic script

tmcw's picture

Here's a really basic script that gets bounding boxes of stuff from a shapefile (and puts the name of the object in the first spot - you'd have to adjust the index of the name column to match): https://gist.github.com/711083

Clue request?

boabjohn's picture

G'day...thanks for the script, that looks useful. Sorry I'm coming in late to the thread, but where is this script supposed to execute?

I too am a point-and-clicker: I did not recognise the script syntax.

I did however recognise the OSGeo reference....am the curious holder of one of their xubuntu DVD treats called Arramagong...heard of it? Was wondering if that script lives somewhere on the disk?

Cheers!

Sorry, this is a Python

tmcw's picture

Sorry, this is a Python script that will require you to edit the filename that it receives and to install OGR and Python if it isn't included on your operating system. You'd invoke it from a terminal like python boxes.py. It's just something I whipped up in a few minutes - I don't know of any point & click tools that will do the same thing.

thanks

sbauch's picture

Much appreciated that you would go out of your way to write something up. I'm using a mac, so I couldn't install OGR but I did get most of the component frameworks. I ran the script on an .shp file I had, and I'm confused by the result. I believe it gives xy min max values for each object in the shapefile (the numbers of lines corresponds to the number of objects), but it looks to me like UTM or a coordinate system I don't know. I tried opening up my shapefile in Qgis and changing the CRS but I can't seem to get that to work. Here are the first two lines of what I get when running the script:

41641860.1953,971113.664700,984473.319800,188447.920400,203989.388600
37739988.0546,980045.093700,987057.852000,200219.045100,209759.147400

The first field I think is an identifier, maybe the object area? The next two fields make sense as xmin and xmax UTM values representing community districts in NYC, as they convert to longitudinal values for NYC. But the last two fields appear to me to be way off, but I'm not sure I totally grasp UTM. I tried converting those values on a free web converting tool, but they appear close to the equator. Am I doing something wrong? Shapefile is here http://www.nyc.gov/html/dcp/download/bytes/nycd_10bav.zip

The shapefile was in a local

tmcw's picture

The shapefile was in a local projection. You need to reproject it, using ogr2ogr or another tool - ogr2ogr t_srs=EPSG:4326 nyc_merc.shp nycd.shp did the trick.

Then it was a matter of changing the j.GetField(2) in the code to j.GetField(0) to correspond with the fact that the ID is the first thing in the columns.

The output I got is here: https://gist.github.com/715597

Thanks so much

sbauch's picture

Thats awesome, thanks so much. I knew I was close, and I did a lot of trial and error and read a good amount about Coordinate Reference Systems, but reprojecting seemed to be a problem a lot of new GIS users were having trouble with.

Drupal community was my #1 thing to be thankful for at Thanksgiving. It would be awesome if there were a way to auto-tag nodes based on the geo-taxonomy bounding box and existing location data (I use Openlayers WKT). I would imagine this is possible by developing a custom module, but I think my time might be better served re-importing my data (which luckily already has NYC community district as a field) rather than writing a custom module. I see that there are modules out there for auto-tagging based on text in the node's content, but I don't see this working for geo-taxonomy out of the box.

Location and Mapping

Group organizers

Group categories

Wiki type

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week