2

My wish is to automate process of lateral erosion. I made it in ModelBuilder and exported it to Python. My input: Excel table with coordinates of measuremant points from 2016 and polygon with shape of riverbank from one of previous years (here from 1979). I add the field "tempo". It has the expression "Shape_Area/55.5". I used Symmetrical Difference for data from 2016 and 1979 it gives me an absolute value of area. In this example it is correct because polygon of 2016 is smaller then polygon of 1979. BUT if polygon of 2016 was bigger then polyon od 1979, the result in field "tempo" should be negative. I should give some kind of if statement, but I'm not sure how. It should be like this but I don't know the right syntax:

If Shape_Area of Wynikowy_poligon_do_analizy > Shape_Area of Dane_z_wcześniejszych_pomiarów: field "tempo" of polygon "dwa_poligony" * (-1)

Where should I put that statement and what is the right syntax?

import arcpy

# Script arguments
Pomiar_tegoroczny = arcpy.GetParameterAsText(0)
if Pomiar_tegoroczny == '#' or not Pomiar_tegoroczny:
    Pomiar_tegoroczny = "C:\\Users\\Ania\\Desktop\\redanedopracyinynierskiej\\wyniki\\punkty_kolej.xlsx" # provide a default value if unspecified

Dane_z_wcześniejszych_pomiarów = arcpy.GetParameterAsText(1)
if Dane_z_wcześniejszych_pomiarów == '#' or not Dane_z_wcześniejszych_pomiarów:
    Dane_z_wcześniejszych_pomiarów = "C:\\Users\\Ania\\Desktop\\redanedopracyinynierskiej\\Dane\\Erozja_boczna_Parseta.gdb\\Odcinki_obserwacyjne_obliczenia\\D3_1979_06_28" # provide a default value if unspecified

Sort_Field = arcpy.GetParameterAsText(2)
if Sort_Field == '#' or not Sort_Field:
    Sort_Field = "kolej" # provide a default value if unspecified

Wyrażenie_na_tempo_erozji = arcpy.GetParameterAsText(3)
if Wyrażenie_na_tempo_erozji == '#' or not Wyrażenie_na_tempo_erozji:
    Wyrażenie_na_tempo_erozji = "[Shape_Area]/55.5" # provide a default value if unspecified

Output = arcpy.GetParameterAsText(4)
if Output == '#' or not Output:
    Output = "tempo_Layer" # provide a default value if unspecified

# Local variables:
punkty_kolej_ExcelToTable = "C:\\Users\\Ania\\Documents\\ArcGIS\\Default.gdb\\punkty_kolej_ExcelToTable"
xdg = "xdg"
FeatureToPoint = "C:\\Users\\Ania\\Documents\\ArcGIS\\Default.gdb\\FeatureToPoint"
FeatureToPoint_PointsToLine = "C:\\Users\\Ania\\Documents\\ArcGIS\\Default.gdb\\FeatureToPoint_PointsToLine"
Wynikowy_poligon_do_analizy = "C:\\Users\\Ania\\Documents\\ArcGIS\\Default.gdb\\punkty2_PointsToLine1_Featur"
tempo = "C:\\Users\\Ania\\Documents\\ArcGIS\\Default.gdb\\tempo"
tempo__2_ = tempo
dwa_poligony = tempo__2_

# Process: Excel To Table
arcpy.ExcelToTable_conversion(Pomiar_tegoroczny, punkty_kolej_ExcelToTable, "Arkusz1")

# Process: Make XY Event Layer
arcpy.MakeXYEventLayer_management(punkty_kolej_ExcelToTable, "POINT_X", "POINT_Y", xdg, "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];-400 -400 1000000000;-100000 10000;-100000 10000;8,98315284119522E-09;0,001;0,001;IsHighPrecision", "")

# Process: Feature To Point
arcpy.FeatureToPoint_management(xdg, FeatureToPoint, "CENTROID")

# Process: Points To Line
arcpy.PointsToLine_management(FeatureToPoint, FeatureToPoint_PointsToLine, "", Sort_Field, "CLOSE")

# Process: Feature To Polygon
arcpy.FeatureToPolygon_management("C:\\Users\\Ania\\Documents\\ArcGIS\\Default.gdb\\FeatureToPoint_PointsToLine", Wynikowy_poligon_do_analizy, "", "ATTRIBUTES", "")

# Process: Symmetrical Difference
arcpy.SymDiff_analysis(Dane_z_wcześniejszych_pomiarów, Wynikowy_poligon_do_analizy, tempo, "NO_FID", "2 Centimeters")

# Process: Add Field
arcpy.AddField_management(tempo, "tempo", "DOUBLE", "2", "2", "", "", "NULLABLE", "NON_REQUIRED", "")

# Process: Calculate Field
arcpy.CalculateField_management(tempo__2_, "tempo", Wyrażenie_na_tempo_erozji, "VB", "")

# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(dwa_poligony, Output, "tempo>0.004", "", "OBJECTID OBJECTID VISIBLE NONE;Shape Shape VISIBLE NONE;Id Id VISIBLE NONE;pow pow VISIBLE NONE;Shape_Length Shape_Length VISIBLE NONE;Shape_Area Shape_Area VISIBLE NONE;Shape_length Shape_length VISIBLE NONE;Shape_area Shape_area VISIBLE NONE;tempo tempo VISIBLE NONE")
1

I don't think your SymDiff output, tempo, can inherit the input Shape_Area field values from pomiarów and analizy (I shortened the names). As a result, it seems you cannot directly access these values in order to compare areas and run a conditional statement in your analysis as you have it structured. However, without severely altering your code, you could instead use a Union operation (rather than SymmDiff). This way you inherit fields in the output that denote where the resulting geometries originated in the form of FID_{your input fc name}. Those fields populated with -1 are essentially a symmetric difference result....so in your case with 2 fcs, a selection query like (FID_pomiarów = -1 or FID_analizy = -1) should give you the equivalent SymDiff output - watch your handling of gaps or improperly overlapping or disjoint polygons. The advantage of this approach is you can in the same output select the FID_pomiarów record(s) and compare area to select FID_analizy record(s) beforehand in order to apply the conditional calculation you desire.

I see you aren't using any cursors which I think would make this work easier and more straightforward, but you can still run the area summary processes separately if need be, adding this to your code - it's just a little slower if you don't have many records.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.