import arcpy import re from itertools import product pnt = arcpy.Point() KEY_VALUE_RE = re.compile(r'([a-z_][a-z0-9_]*)=(\d+(?:\.\d*)?)') def main(): points_to_search_r = [ 'p{0}_{1}w'.format(a, b) for a, b in product([1, 2, 4, 6, 7, 9], 'r') ] points_to_search_h = [ 'p{0}_{1}w'.format(a, b) for a, b in product([1, 2, 4, 6, 7, 9], 'h') ] with open('F:\\Rasterdaten\\SRV\\2005\\TK100\\c4706_3.txt') as lines: for line in lines: variables = dict( (k, float(v)) for k, v in KEY_VALUE_RE.findall(line) ) for point_r in points_to_search_r: value_r = variables.get(point_r) if value_r is not None: #print '{0} {1}'.format(point_r, value_r) pnt.Y = value_r #print pnt.Y for point_h in points_to_search_h: value_h = variables.get(point_h) if value_h is not None: #print '{0} {1}'.format(point_h, value_h) pnt.X = value_h #print pnt.X if __name__ == '__main__': main()
import arcpy arcpy.env.overwriteOutput=1 arcpy.env.workspace = "E:\\mxd\\Shapefiles\\" arcpy.CreateFeatureclass_management(arcpy.env.workspace, "test_polygon.shp","POLYGON") cur=arcpy.InsertCursor("test_polygon.shp") lineArray = arcpy.Array() pnt = arcpy.Point() cur2 = arcpy.SearchCursor("F:\Rasterdaten\SRV\\gps_points.dbf") for row in cur2: pnt.X = row.getValue("x") pnt.Y = row.getValue("y") lineArray.add(pnt) feat = cur.newRow() feat.shape = lineArray cur.insertRow(feat) print "Berechnung beendet" del cur del cur2 del row
Solved! Go to Solution.
import arcpy import re from itertools import product pnt = arcpy.Point() KEY_VALUE_RE = re.compile(r'([a-z_][a-z0-9_]*)=(\d+(?:\.\d*)?)') lineArray = arcpy.Array() def main(): i_cur=arcpy.InsertCursor("test_polygon.shp") # create cursor to insert features points_to_search_r = [ 'p{0}_{1}w'.format(a, b) for a, b in product([1, 2, 4, 6, 7, 9], 'r') ] points_to_search_h = [ 'p{0}_{1}w'.format(a, b) for a, b in product([1, 2, 4, 6, 7, 9], 'h') ] with open('F:\\Rasterdaten\\SRV\\2005\\TK100\\c4706_3.txt') as lines: for line in lines: pnt.X = 0.0 # reset values for each line pnt.Y = 0.0 variables = dict( (k, float(v)) for k, v in KEY_VALUE_RE.findall(line) ) for point_r in points_to_search_r: value_r = variables.get(point_r) if value_r is not None: #print '{0} {1}'.format(point_r, value_r) pnt.Y = value_r #print pnt.Y for point_h in points_to_search_h: value_h = variables.get(point_h) if value_h is not None: #print '{0} {1}'.format(point_h, value_h) pnt.X = value_h #print pnt.X if pnt.X != 0.0 and pnt.Y != 0.0: lineArray.add(pnt) # add point to polyline feat = i_cur.newRow() feat.SHAPE = lineArray i_cur.insertRow(feat) del i_cur if __name__ == '__main__': main()
import arcpy import re from itertools import product pnt = arcpy.Point() KEY_VALUE_RE = re.compile(r'([a-z_][a-z0-9_]*)=(\d+(?:\.\d*)?)') #lineArray = arcpy.Array() def main(): i_cur=arcpy.InsertCursor("test_polygon.shp") # create cursor to insert features points_to_search_r = [ 'p{0}_{1}w'.format(a, b) for a, b in product([1, 2, 4, 6, 7, 9], 'r') ] points_to_search_h = [ 'p{0}_{1}w'.format(a, b) for a, b in product([1, 2, 4, 6, 7, 9], 'h') ] with open('F:\\Rasterdaten\\SRV\\2005\\TK100\\c4706_3.txt') as lines: for line in lines: pnt.X = 0.0 # reset values for each line pnt.Y = 0.0 variables = dict( (k, float(v)) for k, v in KEY_VALUE_RE.findall(line) ) for point_r in points_to_search_r: value_r = variables.get(point_r) if value_r is not None: #print '{0} {1}'.format(point_r, value_r) pnt.Y = value_r #print pnt.Y for point_h in points_to_search_h: value_h = variables.get(point_h) if value_h is not None: #print '{0} {1}'.format(point_h, value_h) pnt.X = value_h #print pnt.X if pnt.X != 0.0 and pnt.Y != 0.0: feat = i_cur.newRow() feat.SHAPE = pnt i_cur.insertRow(feat) del i_cur if __name__ == '__main__': main()
import arcpy import re from itertools import product pnt = arcpy.Point() KEY_VALUE_RE = re.compile(r'([a-z_][a-z0-9_]*)=(\d+(?:\.\d*)?)') lineArray = arcpy.Array() def main(): i_cur=arcpy.InsertCursor("test_polygon.shp") # create cursor to insert features points_to_search_r = [ 'p{0}_{1}w'.format(a, b) for a, b in product([1, 2, 4, 6, 7, 9], 'r') ] points_to_search_h = [ 'p{0}_{1}w'.format(a, b) for a, b in product([1, 2, 4, 6, 7, 9], 'h') ] with open('F:\\Rasterdaten\\SRV\\2005\\TK100\\c4706_3.txt') as lines: for line in lines: pnt.X = 0.0 # reset values for each line pnt.Y = 0.0 variables = dict( (k, float(v)) for k, v in KEY_VALUE_RE.findall(line) ) for point_r in points_to_search_r: value_r = variables.get(point_r) if value_r is not None: #print '{0} {1}'.format(point_r, value_r) pnt.Y = value_r #print pnt.Y for point_h in points_to_search_h: value_h = variables.get(point_h) if value_h is not None: #print '{0} {1}'.format(point_h, value_h) pnt.X = value_h #print pnt.X if pnt.X != 0.0 and pnt.Y != 0.0: lineArray.add(pnt) # add point to polyline feat = i_cur.newRow() feat.SHAPE = lineArray i_cur.insertRow(feat) del i_cur if __name__ == '__main__': main()
import arcpy import re from itertools import product pnt = arcpy.Point() KEY_VALUE_RE = re.compile(r'([a-z_][a-z0-9_]*)=(\d+(?:\.\d*)?)') #lineArray = arcpy.Array() def main(): i_cur=arcpy.InsertCursor("test_polygon.shp") # create cursor to insert features points_to_search_r = [ 'p{0}_{1}w'.format(a, b) for a, b in product([1, 2, 4, 6, 7, 9], 'r') ] points_to_search_h = [ 'p{0}_{1}w'.format(a, b) for a, b in product([1, 2, 4, 6, 7, 9], 'h') ] with open('F:\\Rasterdaten\\SRV\\2005\\TK100\\c4706_3.txt') as lines: for line in lines: pnt.X = 0.0 # reset values for each line pnt.Y = 0.0 variables = dict( (k, float(v)) for k, v in KEY_VALUE_RE.findall(line) ) for point_r in points_to_search_r: value_r = variables.get(point_r) if value_r is not None: #print '{0} {1}'.format(point_r, value_r) pnt.Y = value_r #print pnt.Y for point_h in points_to_search_h: value_h = variables.get(point_h) if value_h is not None: #print '{0} {1}'.format(point_h, value_h) pnt.X = value_h #print pnt.X if pnt.X != 0.0 and pnt.Y != 0.0: feat = i_cur.newRow() feat.SHAPE = pnt i_cur.insertRow(feat) del i_cur if __name__ == '__main__': main()