Pages

Monday, December 15, 2014

GPX2SHP

Here's a nice Garmin GPX to shapefile converter using PyShp by Matt Rantala from his blog MapRantala.com:


Photo: FishStickTheatre.com

Wednesday, December 3, 2014

WKT EPSG Strings Made Easy

This quick post is a follow on to my posts on map projections and creating .prj files for shapefiles.
 The .prj file format created by Esri originally but now recognized by most geospatial software is just a text file with a WKT string for the projection information.  Most of projections can be referenced by a simple EPSG code which is just a number.  Usually you'll have this number handy and need to look up the full WKT string on SpatialReference.org.

Dr. David Forrest, a research scientist at the Virginia Institute of Marine Sciences, sent me a simple function to make fetching WKT projection strings easy:

def getPRJwkt(epsg):
   """
   Grab an WKT version of an EPSG code
   usage getPRJwkt(4326)

   This makes use of links like 
   http://spatialreference.org/ref/epsg/4326/prettywkt/
   """
   
   import urllib
   sr = "http://spatialreference.org"
   f=urllib.urlopen(sr + "/ref/epsg/{0}/prettywkt/".format(epsg))
   return (f.read())

So then getting a WKT projection string is as easy as:

>>> wkt = getPRJwkt(4326)
>>> print wkt
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.01745329251994328,
        AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4326"]]

There's another, newer website called epsg.io that has some additional features beyond spatialreference.org.  The differences are in the FAQ on this page.

Monday, December 1, 2014

Errata

In Chapter 8 of my book, the shapefile doesn't have a .prj file which isn't a big deal for the example

but can be annoying if you try to open it in QGIS or ArcGIS.  There was also an unused numpy array in the example so I updated the whole package.  You can download the updated script and data here:
https://geospatialpython.googlecode.com/svn/NDVI-update.zip

This example is the very first example in the chapter.  The second example shows you how to classify the output data.

"Learning Geospatial Analysis with Python" Cyber Monday Sale

The print edition of Learning Geospatial Analysis with Python qualifies for a 30% discount on Amazon.com until midnight tonight using discount code HOLIDAY30 at checkout.  This is for the print edition only which is black and white as are most programming books as opposed to the eBook which is full color.  Very soon I will make an image catalog available for download for people with the print edition.  This detail isn't critical as most of the illustrations are not color dependent with the exception of a 1 or 2 remote sensing examples where color is helpful.  The image catalog will give you the best of both worlds and with a 30% savings to boot!