import arcgisscripting gp = arcgisscripting.create(9.3) fc = r"\\snarf\am\div_lm\ds\gis\tools\sde_connections_read\ropa_gis_layer_user.sde\CADASTRE.TOWNSHIP_SV" spatialRef = r"C:\Program Files\ArcGIS\Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj" dsc = gp.describe(fc) shapeFieldName = dsc.shapeFieldName oidFieldName = dsc.oidfieldname searchRows = gp.searchcursor(fc, "", spatialRef) searchRow = searchRows.next() while searchRow: oidFieldValue = searchRow.getvalue(oidFieldName) print oidFieldName + " = " + str(oidFieldValue) shapeFieldObj = searchRow.getvalue(shapeFieldName) partCount = shapeFieldObj.partcount partIndex = 0 while partIndex < partCount: print "Part " + str(partIndex)+ ":" partObj = shapeFieldObj.GetPart(partIndex) pointObj = partObj.next() pointCounter = 0 while pointObj: print pointObj.x, pointObj.y pointObj = partObj.next() pointCounter += 1 # If pointObj is null, either the part is finished or there is an interior ring if not pointObj: pointObj = partObj.next() if pointObj: print "Interior Ring:" partIndex += 1 searchRow = searchRows.next()
def angle(pointlist): # calculates using cosine rule: A^2 = B^2 + C^2 - 2BC cos a # a = arccos ((B^2+C^2-A^2)/(2BC)) # but multiply by 180/pi to convert from radians A_vector = pointlist[0] - pointlist[2] B_vector = pointlist[0] - pointlist[1] C_vector = pointlist[1] - pointlist[2] A2,B2,C2 = map(square_length_of_vector,(A_vector,B_vector,C_vector)) B,C = map(numpy.sqrt,(B2,C2)) side_ratio = (B2+C2-A2)/(2*B*C) if side_ratio > 1: # possible on sharp angle due to rounding errors return 0. elif side_ratio < -1: # possible on blunt angle due to rounding errors return 180. else: return 180/numpy.pi * numpy.arccos(side_ratio)
import arcgisscripting gp = arcgisscripting.create(9.3) fc = r"\\snarf\am\div_lm\ds\gis\tools\sde_connections_read\ropa_gis_layer_user.sde\CADASTRE.TOWNSHIP_SV" spatialRef = r"C:\Program Files\ArcGIS\Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj" dsc = gp.describe(fc) shapeFieldName = dsc.shapeFieldName oidFieldName = dsc.oidfieldname searchRows = gp.searchcursor(fc, "", spatialRef) searchRow = searchRows.next() while searchRow: oidFieldValue = searchRow.getvalue(oidFieldName) print oidFieldName + " = " + str(oidFieldValue) shapeFieldObj = searchRow.getvalue(shapeFieldName) partCount = shapeFieldObj.partcount partIndex = 0 while partIndex < partCount: print "Part " + str(partIndex)+ ":" partObj = shapeFieldObj.GetPart(partIndex) pointObj = partObj.next() pointCounter = 0 while pointObj: print pointObj.x, pointObj.y pointObj = partObj.next() pointCounter += 1 # If pointObj is null, either the part is finished or there is an interior ring if not pointObj: pointObj = partObj.next() if pointObj: print "Interior Ring:" partIndex += 1 searchRow = searchRows.next()
You can make rapid coordinate system conversions by using an appropriate spatial reference parameter in a cursor.