This tutorial uses data provided from our website and OGR2OGR to generate a shapefile of rare EOs (element occurrences) for animals, plants and natural communitiy locations in Georgia, USA, generalized to 1/4 of a USGS 7.5 minute topo map .
OGR2OGR is a free command line program that is able to manipulate GIS vector and associated attribute data in many ways including doing reprojections. It can also convert GIS vector data and non GIS data tables between many common formats such as ESRI Shapefile , ESRI Personal GeoDatabase , SQLite/SpatiaLite , KML , and many others .
Below is a Windows batch file that uses ogr2ogr first to load qq.shp and qq_eos.csv into a temporary SpatiaLite spatial database file. Then ogr2ogr is used to run an SQL left join query to add quarter quad polygons from qq.shp to associated qq_eos records and output a shapefile.
- The data is passed first to an SQLite database to speed up the procedure and simplify the code.
- Installing SQLite with SpatiaLite is not required to run this procedure.
- These same procedures can be used with data for Georgia counties, and HUC8 and HUC 10 watersheds from our Rare Species Location page .
- All vector data in this tutorial uses a spatial reference system of NAD 83 UTM Zone 17N (EPSG:26917).
- Install GDAL version 1.8.0 or greater (contains OGR2OGR).
- Place qq_eos.csv , qq.shp and qq_eos_shp.bat in a directory by themselves.
- Run the qq_eos_shp.bat by double clicking on it in Windows or run it from the command line.
Contents of qq_eos_shp.bat:
REM Delete the sqlite database if it already exists
REM Delete the output shapefile if it already exists
REM Create a temporary SQLite (SpatialLite) database and copy qq.shp into it.
ogr2ogr -f SQLite tmp.sqlite qq.shp
REM Copy the CSV file into the SQLite database
ogr2ogr -update -f SQLite tmp.sqlite qq_eos.csv
REM Left join qq shapes to the CSV attribute table and output a shapefile. Create projection file.
ogr2ogr -overwrite -f "ESRI Shapefile" qq_eos_out.shp tmp.sqlite -a_srs EPSG:26917 -sql "SELECT * FROM qq_eos LEFT JOIN qq ON qq_eos.id_code = qq.area_code"
REM Delete the temporary database