[Gdal-dev] OGR and Python. Accessing spatial data from non-spatial tables

Sampson, David dsampson at NRCan.gc.ca
Fri Feb 16 07:35:53 EST 2007


Hey Folks,

I'm looking for help using OGR and python. I am pretty novice with
python at this stage so I think I am loosing sight of what objects need
to be made. Some guidance would be great.

I am trying to create polygons (rectangles) from an ODBC connection to a
non-spatial table.

In all I need to access 8 collumns (x and y for four points)

Each polygon is defined by a single row

Groups of rows exist based on a SEGMENT collumn. Each group could have
upwards of 100 polygons.

This is some of the code I have been working on

def odbc_Footprint():
	DSN="*****"
	UID="*****"
	PW="*****"
	TBL="*****"	
	update_status = "0"
	SQL_Collumn = "ID"
	SQL_Collumn_value = "'257775'" 
	NW_X=ogr.Open("ODBC:" + UID + "/" + PW + "@" + DSN + "," + TBL
+"(X_NO)", update = int(update_status))
	NW_Y=ogr.Open("ODBC:" + UID + "/" + PW + "@" + DSN + "," + TBL
+"(Y_NO)", update = int(update_status))
	NE_X=ogr.Open("ODBC:" + UID + "/" + PW + "@" + DSN + "," + TBL
+"(X_NE)", update = int(update_status))
	NE_Y=ogr.Open("ODBC:" + UID + "/" + PW + "@" + DSN + "," + TBL
+"(Y_NE)", update = int(update_status))
	SW_X=ogr.Open("ODBC:" + UID + "/" + PW + "@" + DSN + "," + TBL
+"(X_SO)", update = int(update_status))
	SW_Y=ogr.Open("ODBC:" + UID + "/" + PW + "@" + DSN + "," + TBL
+"(Y_SO)", update = int(update_status))
	SE_X=ogr.Open("ODBC:" + UID + "/" + PW + "@" + DSN + "," + TBL
+"(X_SE)", update = int(update_status))
	SE_Y=ogr.Open("ODBC:" + UID + "/" + PW + "@" + DSN + "," + TBL
+"(Y_SE)", update = int(update_status))
	

	# SQL Calls
	SQL_NW_X = NW_X.ExecuteSQL("Select * from " + TBL + " where " +
SQL_Collumn + " = " + SQL_Collumn_value )
	SQL_NW_Y = NW_Y.ExecuteSQL("Select * from " + TBL + " where " +
SQL_Collumn + " = " + SQL_Collumn_value )
	SQL_NE_X = NE_X.ExecuteSQL("Select * from " + TBL + " where " +
SQL_Collumn + " = " + SQL_Collumn_value )
	SQL_NE_Y = NE_Y.ExecuteSQL("Select * from " + TBL + " where " +
SQL_Collumn + " = " + SQL_Collumn_value )
	SQL_SW_X = SW_X.ExecuteSQL("Select * from " + TBL + " where " +
SQL_Collumn + " = " + SQL_Collumn_value )	
	SQL_SW_Y = SW_Y.ExecuteSQL("Select * from " + TBL + " where " +
SQL_Collumn + " = " + SQL_Collumn_value )
	SQL_SE_X = SE_X.ExecuteSQL("Select * from " + TBL + " where " +
SQL_Collumn + " = " + SQL_Collumn_value )
	SQL_SE_Y = SE_Y.ExecuteSQL("Select * from " + TBL + " where " +
SQL_Collumn + " = " + SQL_Collumn_value )

	NW = (SQL_NW_X, SQL_NW_Y)
	NE = (SQL_NE_X, SQL_NE_Y)
	SW = (SQL_SW_X, SQL_SW_Y)
	SE = (SQL_SE_X, SQL_SE_Y)

Python help for OGR is a little sparse and I don't have a C background.

These are some sources I have tried to use to get this far.
Python with postgres:
http://postgis.refractions.net/support/wiki/index.php?OGR%20Examples
OGR ODBC: http://www.gdal.org/ogr/drv_odbc.html
OpenEV Dev Course:
http://openev.sourceforge.net/app/developer_info/DEVCOURSE.html
Gdal python tutorial: http://www.gdal.org/gdal_tutorial.html


Thanks for any help.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20070216/c2ee649a/attachment.html


More information about the Gdal-dev mailing list