<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7651.14">
<TITLE>OGR and Python. Accessing spatial data from non-spatial tables</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><FONT SIZE=2 FACE="Arial">Hey Folks,</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">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.</FONT></P>
<P><FONT SIZE=2 FACE="Arial">I am trying to create polygons (rectangles) from an ODBC connection to a non-spatial table.</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">In all I need to access 8 collumns (x and y for four points)</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Each polygon is defined by a single row</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Groups of rows exist based on a SEGMENT collumn. Each group could have upwards of 100 polygons.</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">This is some of the code I have been working on</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">def odbc_Footprint():</FONT>
<BR> <FONT SIZE=2 FACE="Arial">DSN="*****"</FONT>
<BR> <FONT SIZE=2 FACE="Arial">UID="*****"</FONT>
<BR> <FONT SIZE=2 FACE="Arial">PW="*****"</FONT>
<BR> <FONT SIZE=2 FACE="Arial">TBL="*****" </FONT>
<BR> <FONT SIZE=2 FACE="Arial">update_status = "0"</FONT>
<BR> <FONT SIZE=2 FACE="Arial">SQL_Collumn = "ID"</FONT>
<BR> <FONT SIZE=2 FACE="Arial">SQL_Collumn_value = "'257775'" </FONT>
<BR> <FONT SIZE=2 FACE="Arial">NW_X=ogr.Open("ODBC:" + UID + "/" + PW + "@" + DSN + "," + TBL +"(X_NO)", update = int(update_status))</FONT>
<BR> <FONT SIZE=2 FACE="Arial">NW_Y=ogr.Open("ODBC:" + UID + "/" + PW + "@" + DSN + "," + TBL +"(Y_NO)", update = int(update_status))</FONT>
<BR> <FONT SIZE=2 FACE="Arial">NE_X=ogr.Open("ODBC:" + UID + "/" + PW + "@" + DSN + "," + TBL +"(X_NE)", update = int(update_status))</FONT>
<BR> <FONT SIZE=2 FACE="Arial">NE_Y=ogr.Open("ODBC:" + UID + "/" + PW + "@" + DSN + "," + TBL +"(Y_NE)", update = int(update_status))</FONT>
<BR> <FONT SIZE=2 FACE="Arial">SW_X=ogr.Open("ODBC:" + UID + "/" + PW + "@" + DSN + "," + TBL +"(X_SO)", update = int(update_status))</FONT>
<BR> <FONT SIZE=2 FACE="Arial">SW_Y=ogr.Open("ODBC:" + UID + "/" + PW + "@" + DSN + "," + TBL +"(Y_SO)", update = int(update_status))</FONT>
<BR> <FONT SIZE=2 FACE="Arial">SE_X=ogr.Open("ODBC:" + UID + "/" + PW + "@" + DSN + "," + TBL +"(X_SE)", update = int(update_status))</FONT>
<BR> <FONT SIZE=2 FACE="Arial">SE_Y=ogr.Open("ODBC:" + UID + "/" + PW + "@" + DSN + "," + TBL +"(Y_SE)", update = int(update_status))</FONT>
<BR>
</P>
<P> <FONT SIZE=2 FACE="Arial"># SQL Calls</FONT>
<BR> <FONT SIZE=2 FACE="Arial">SQL_NW_X = NW_X.ExecuteSQL("Select * from " + TBL + " where " + SQL_Collumn + " = " + SQL_Collumn_value )</FONT>
<BR> <FONT SIZE=2 FACE="Arial">SQL_NW_Y = NW_Y.ExecuteSQL("Select * from " + TBL + " where " + SQL_Collumn + " = " + SQL_Collumn_value )</FONT>
<BR> <FONT SIZE=2 FACE="Arial">SQL_NE_X = NE_X.ExecuteSQL("Select * from " + TBL + " where " + SQL_Collumn + " = " + SQL_Collumn_value )</FONT>
<BR> <FONT SIZE=2 FACE="Arial">SQL_NE_Y = NE_Y.ExecuteSQL("Select * from " + TBL + " where " + SQL_Collumn + " = " + SQL_Collumn_value )</FONT>
<BR> <FONT SIZE=2 FACE="Arial">SQL_SW_X = SW_X.ExecuteSQL("Select * from " + TBL + " where " + SQL_Collumn + " = " + SQL_Collumn_value ) </FONT></P>
<P> <FONT SIZE=2 FACE="Arial">SQL_SW_Y = SW_Y.ExecuteSQL("Select * from " + TBL + " where " + SQL_Collumn + " = " + SQL_Collumn_value )</FONT>
<BR> <FONT SIZE=2 FACE="Arial">SQL_SE_X = SE_X.ExecuteSQL("Select * from " + TBL + " where " + SQL_Collumn + " = " + SQL_Collumn_value )</FONT>
<BR> <FONT SIZE=2 FACE="Arial">SQL_SE_Y = SE_Y.ExecuteSQL("Select * from " + TBL + " where " + SQL_Collumn + " = " + SQL_Collumn_value )</FONT>
</P>
<P> <FONT SIZE=2 FACE="Arial">NW = (SQL_NW_X, SQL_NW_Y)</FONT>
<BR> <FONT SIZE=2 FACE="Arial">NE = (SQL_NE_X, SQL_NE_Y)</FONT>
<BR> <FONT SIZE=2 FACE="Arial">SW = (SQL_SW_X, SQL_SW_Y)</FONT>
<BR> <FONT SIZE=2 FACE="Arial">SE = (SQL_SE_X, SQL_SE_Y)</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Python help for OGR is a little sparse and I don't have a C background.</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">These are some sources I have tried to use to get this far.</FONT>
<BR><FONT SIZE=2 FACE="Arial">Python with postgres: </FONT><A HREF="http://postgis.refractions.net/support/wiki/index.php?OGR%20Examples"><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">http://postgis.refractions.net/support/wiki/index.php?OGR%20Examples</FONT></U></A>
<BR><FONT SIZE=2 FACE="Arial">OGR ODBC: </FONT><A HREF="http://www.gdal.org/ogr/drv_odbc.html"><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">http://www.gdal.org/ogr/drv_odbc.html</FONT></U></A>
<BR><FONT SIZE=2 FACE="Arial">OpenEV Dev Course: </FONT><A HREF="http://openev.sourceforge.net/app/developer_info/DEVCOURSE.html"><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">http://openev.sourceforge.net/app/developer_info/DEVCOURSE.html</FONT></U></A>
<BR><FONT SIZE=2 FACE="Arial">Gdal python tutorial: </FONT><A HREF="http://www.gdal.org/gdal_tutorial.html"><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">http://www.gdal.org/gdal_tutorial.html</FONT></U></A>
</P>
<BR>
<P><FONT SIZE=2 FACE="Arial">Thanks for any help.</FONT>
</P>
<BR>
</BODY>
</HTML>