Loading data into PostGIS

From Wildsong
Revision as of 18:49, 3 July 2009 by Brian Wilson (talk | contribs)
Jump to navigationJump to search


Paulo Corti's notes on Migrating shapefiles to PostGIS from "Thinking in GIS"

What I am really about on this page is using Python to transfer data from ESRI proprietary formats into PostGIS.

You need an ArcGIS license for this to access the ESRI formats. If your data are in shapefiles you don't need this...

I already know how to iterate over an ESRI feature class using a cursor. I might have trouble with the geometry... pretty sure I can do it though, especially for point files! Points are easy.

Iterate a feature class

Here is a simple script to iterate over a feature class and read its geometry. The nice thing about using the ESRI code for this is that it does not matter what the data source is, it's just a 'feature class' that can be stored in a shapefile or a personal geodatabase or ArcSDE... etc...

import arcgisscripting 
gp = arcgisscripting.create(9.3)

# Hard coded data source, for simplicity.
workspace = 'D:/AGIProducts/IncidentView_Data/Data/WA/South_King/IncidentView.mdb'
featureclass = 'Address_points'

gp.workspace = workspace
desc = gp.describe(featureclass)
fields = gp.GetFields(fcname, '*') # Get a list of the attributes

rows = gp.SearchCursor(featureclass)
row = rows.Next()
while (row)
{
     geom = row.geometry()
     # We have geometry and attributes.
     # We should do something with them here, eh?
     row = rows.Next()
}