Loading data into PostGIS: Difference between revisions
Brian Wilson (talk | contribs) mNo edit summary |
Brian Wilson (talk | contribs) |
||
Line 25: | Line 25: | ||
gp.workspace = workspace | gp.workspace = workspace | ||
desc = gp.describe(featureclass) | desc = gp.describe(featureclass) # Get some metadata | ||
fields = gp.GetFields(fcname, '*') # Get a list of the attributes | fields = gp.GetFields(fcname, '*') # Get a list of the attributes | ||
rows = gp.SearchCursor(featureclass) | rows = gp.SearchCursor(featureclass) | ||
row = rows.Next() | row = rows.Next() | ||
while | while row: | ||
{ | { | ||
geom = row.geometry() | geom = row.geometry() |
Revision as of 19:20, 3 July 2009
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) # Get some metadata 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() }