lundi 29 décembre 2014

Loop does not move on to the next row?


As you can see in the First picture, I have parcel 220, and i want to determinate the position of each of his neighbor ! So the idea was to calculate the bearing between the centroinde of 220, and the other centroid of neighbors (when the bearing is between [50,150] = North; [150, 250]= East; [250,350]= West ...). So to determinate the neighbors i use the function arcpy.PolygonNeighbors_analysis (in_features, out_table, {in_fields})(Picture 2), and at the picture 3, we have a parcels with centroide (X,Y). So each time i should take



  1. (X,Y) of P220 as start Point and (X,Y) of P228 as end point than calculate bearing

  2. (X,Y) of P220 as start Point and (X,Y) of P227 as end point, calculate bearing

  3. (X,Y) of P220 as start Point and (X,Y) of P226 as end point, calculate bearing

  4. than for all the neighbors on the Picture 2


Picture 1 Picture 2 Picture 3 For doing this I used three loop for, and I think it's turning right, but it does it just for the first row, and doesn't move to the newt row!


The code is this:



>>> cur = arcpy.UpdateCursor("Join_Output_12")
>>> cur2 = arcpy.UpdateCursor("Join_Output_12")
>>> cur_t = arcpy.UpdateCursor("tb20_12_2014_")
>>> del row2, Refname__table_neighbor, start_x1, start_y1, end_x1, end_y1, copy_field
>>> for row in cur :
... Refname_feature = row.getValue("RefName")
... for row_t in cur_t :
... Refname__table_target = row_t.getValue("src_RefName")
... if(Refname__table_target==Refname_feature):
... start_x1 = row.getValue("POINT_X")
... start_y1 = row.getValue("POINT_Y")
... print Refname_feature
... print start_x1
... print start_y1
... Refname__table_neighbor = row_t.getValue("nbr_RefName")
... print Refname__table_neighbor
... for row2 in cur2 :
... copy_field = row2.getValue("copy_field")
... if (copy_field==Refname__table_neighbor):
... end_x1 = row2.getValue("POINT_X")
... end_y1 = row2.getValue("POINT_Y")
... print copy_field
... print end_x1
... print end_y1
... row = cur.next()


The result is:



1
221408.8543
200288.7235
1
1
221408.8543
200288.7235


So I think that the problem comes from for loop!


Now after getting this result, that you can see on the picture 4 (Position off each parcel) Picture 4 The result i get was good! But it doesn't respond at 100% to my need, to be more clear let's see the example of parcel 221, it has parcel neighbor 220 at North and also West, but at the table we can see just North, for that i want to canncatenate this result to the result of the function CalculateAdjacentFields_cartography (in_features, in_field) you will tell me why just not to use only this function ? but it's also uncomplete ! look at picture 5 to see the result Picture 5 Let's take the exmaple P220, we can see that it sets just 224, 226 on North, even if there is More ! So the idea is to concatenade the two results to get at last one more complete and reliable result ! But how to do it ? i can't find one logic to combinate them !!





Aucun commentaire:

Enregistrer un commentaire