Archive for the 'gis' Category

Using OGR to convert GIS Vector formats

OGR is a part of GDAL and is very useful for converting between geospatial vector formats. What does that mean? When storing Vector GIS data there are a dizzying number of formats it can be stored in, some of the more popular of late, or at least well known are KML and SHP. A friend of a friend was looking to convert some SHP (Shapefiles) into KML so that he could make a Google Maps mashup and I helped him out. Here is a workflow for how I went about performing the conversion.

OGR can be installed on debian/ubuntu machines by installing the package gdal-bin:

sudo apt-get install gdal-bin

Once you have GDAL/OGR installed you get a slew of command line utilities, I’ll try to cover some others in later tutorials, but for now we’re interested in ogr2ogr. ogr2ogr converts between the vector formats that OGR understands.

Example using a shapefile at the city of chicago website:
Download the data

wget http://egov.cityofchicago.org/webportal/COCWebPortal/COC_ATTACH/TIFS2008.zip

Unzip it

unzip TIFS2008.zip

Now we have to do the hard part (not really that hard, but important), look for the projection information in the metadata. I looked in the tifs.shp.xml file and found that the projections is:

NAD_1983_StatePlane_Illinois_East_FIPS_1201_Feet

Google uses WGS84 spatial reference system.
Now we have to lookup EPSG codes that OGR understands for these projections. A good spot to do this is spatialreference.org. EPSG codes provide a short form of expressing projection and spatial reference information.
Once we have that all sorted out we’re ready to run ogr2ogr:

ogr2ogr -f "KML" -s_srs "EPSG:102671" -t_srs "EPSG:4326" tifs.kml tifs.shp

The -f “KML” specifies that we want the output in KML. -s_srs is the source (tifs.shp) spatial reference system and -t_srs is the target spatial reference system found at spatialreference.org, then we specify the output file tifs.kml and the input file tifs.shp. That is it!

Lets shrink it down into a kmz (compressed kml) so that it takes up less disk space.

zip tifs.kmz tifs.kml

Getting to know PostGIS

I am making the plunge to get more informed with how to use PostGIS. It is pretty impressive so far. Here is a quick tutorial which shows you how to get started and loading in a shapefile to play around with some fun SQL querying. I assume a basic understanding of the linux command line and some basic SQL skills.

To get started in ubuntu 7.04 (should work in 7.10 and debian too):

$ sudo apt-get install postgis postgresql-8.1-postgis

Next we’ll start setting up the PostGIS environment.
Continue reading ‘Getting to know PostGIS’

San Diego Fires on MODIS

Just whipped together an animation of the San Diego Fires from some recent MODIS scenes that I grabbed from the MODIS Rapid Response System. I put the animation together using GIMP.

San Diego Fires
(Click for Larger Version 1.9MB)

Woowee…

The blog is getting mighty impersonal with all those del.icio.us posts. Maybe that can serve as a reminder for me to post more.

I have been hacking on a bunch of convenience code in python for the LTM (Land Transformation Model) which serves as the land use projection portion of my research. Basically just wrapping a bunch of ArcGIS functions that do what I need done and then some file manipulation and config file writing before I launch code written by our postdoc. Going to try and do some time projections for all of the state of Indiana and then go back to my Muskegon study area with the new tools to re-run the model up there. It should make things run much more smoothly.

Quick and dirty GIS Server

Here is a quick and dirty ArcGIS geoprocessing server. I mostly did this so that I can call ArcGIS routines from scripts on my linux box across a cluster of ArcGIS servers.

It is not without caveats, mostly security caveats. I work in a firewalled environment and would not recommend exposing the entire arcgisscripting geoprocessing object in a non-firewalled environment, without adding some security. With the client code I am able to write scripts that work on either Win32 or Linux with the same code.

Additionally, you will need to refer to files and directories in your scripts as they would appear to the server instance (with its windows permissions). As ArcGIS scripting routines do not directly allow the passing of GIS data to them, you will have to point to them on the server’s filesystem, geodatabase or remote ArcSDE server as you would locally on the server.
Continue reading ‘Quick and dirty GIS Server’

geopy

Stumbled upon geopy while looking through a fantastic list of OSS and Linux GIS tools.

Geopy lets me code a geocoder in 6 lines of python using the google maps API.

Continue reading ‘geopy’

Histogram of an ASCII Raster

Warning, esoteric GIS related post follows.

I often like to be able to generate a quick histogram of an ASCII raster file that I use for some of my models. I can do this inside of ArcGIS on a GRID file, but I like to be able to do this directly on an ASCII sometimes. Python to the rescue…

Continue reading ‘Histogram of an ASCII Raster’