1

The idea of my script is to create a new layer which will be a layer of districts in the city based on a layer of parcels. The attribute table of parcels has one field that should be used to determine which parcels are from which district.

enter image description here

I managed to do it for one district, but I have no idea how to make it work for all of them, no matter how many parcels or districts are in layer.

import arcpy

arcpy.env.workspace = r"D:\Studia\python'\roboczapy.gdb"

##City shapefile
obreb = r"D:\Studia\python'\P3_Dane\Gdansk_22.shp"

cursor = arcpy.SearchCursor (obreb, fields="IDENTYFIKA")

##Creating a new layer
nowawarstwa = arcpy.MakeFeatureLayer_management(obreb, out_layer="Gdansk_22_Lyr", field_info="FID FID VISIBLE NONE;Shape Shape VISIBLE NONE;OBJECTID OBJECTID VISIBLE NONE;IDENTYFIKA IDENTYFIKA VISIBLE NONE;POWIERZCHN POWIERZCHN VISIBLE NONE;TERYT TERYT VISIBLE NONE;NUMER NUMER VISIBLE NONE;WOJEWODZTW WOJEWODZTW VISIBLE NONE;POWIAT POWIAT VISIBLE NONE;GMINA GMINA VISIBLE NONE;DATA_OD DATA_OD VISIBLE NONE;Shape_Leng Shape_Leng VISIBLE NONE;Shape_Area Shape_Area VISIBLE NONE;obreb obreb VISIBLE NONE;obreby obreby VISIBLE NONE")
arcpy.SaveToLayerFile_management(nowawarstwa, "Gdansk22Lyr", "ABSOLUTE")

## Selecting and exporting to another layer only those parcels from first district using clause [where_clause=""""IDENTYFIKA" LIKE '226101_1.0001.%'"""]
obreb1 = arcpy.FeatureClassToFeatureClass_conversion(obreb, out_path="D:/Studia/python'/roboczapy.gdb", out_name="obreb1", where_clause=""""IDENTYFIKA" LIKE '226101_1.0001.%'""", field_mapping="""OBJECTID "OBJECTID" true true false 11 Double 0 11 ,First,#,D:\Studia\python'\P3_Dane\Gdansk_22.shp,OBJECTID,-1,-1;IDENTYFIKA "IDENTYFIKA" true true false 100 Text 0 0 ,First,#,D:\Studia\python'\P3_Dane\Gdansk_22.shp,IDENTYFIKA,-1,-1;POWIERZCHN "POWIERZCHN" true true false 19 Double 15 18 ,First,#,D:\Studia\python'\P3_Dane\Gdansk_22.shp,POWIERZCHN,-1,-1;TERYT "TERYT" true true false 7 Text 0 0 ,First,#,D:\Studia\python'\P3_Dane\Gdansk_22.shp,TERYT,-1,-1;NUMER "NUMER" true true false 50 Text 0 0 ,First,#,D:\Studia\python'\P3_Dane\Gdansk_22.shp,NUMER,-1,-1;WOJEWODZTW "WOJEWODZTW" true true false 254 Text 0 0 ,First,#,D:\Studia\python'\P3_Dane\Gdansk_22.shp,WOJEWODZTW,-1,-1;POWIAT "POWIAT" true true false 254 Text 0 0 ,First,#,D:\Studia\python'\P3_Dane\Gdansk_22.shp,POWIAT,-1,-1;GMINA "GMINA" true true false 254 Text 0 0 ,First,#,D:\Studia\python'\P3_Dane\Gdansk_22.shp,GMINA,-1,-1;DATA_OD "DATA_OD" true true false 8 Date 0 0 ,First,#,D:\Studia\python'\P3_Dane\Gdansk_22.shp,DATA_OD,-1,-1;Shape_Leng "Shape_Leng" true true false 19 Double 15 18 ,First,#,D:\Studia\python'\P3_Dane\Gdansk_22.shp,Shape_Leng,-1,-1;Shape_Area "Shape_Area" true true false 19 Double 15 18 ,First,#,D:\Studia\python'\P3_Dane\Gdansk_22.shp,Shape_Area,-1,-1;obreb "obreb" true true false 5 Short 0 5 ,First,#,D:\Studia\python'\P3_Dane\Gdansk_22.shp,obreb,-1,-1;obreby "obreby" true true false 5 Short 0 5 ,First,#,D:\Studia\python'\P3_Dane\Gdansk_22.shp,obreby,-1,-1""", config_keyword="")

## Dissolving this one selected district with additional information about average area of parcells, STD of parcels are - but there should be median and highest parcel number in district 
arcpy.Dissolve_management(in_features="obreb1", out_feature_class="D:/Studia/python'/roboczapy.gdb/dissolveobreb1", dissolve_field="", statistics_fields="POWIERZCHN MEAN;POWIERZCHN STD;IDENTYFIKA MAX", multi_part="MULTI_PART", unsplit_lines="DISSOLVE_LINES")

print "end"

Some things here look terrible because Copyied Snippets from ArcMap to Python.

Despite dissolving, the attribute table in new layer should contain fields like district number, average parcel area, median of parcel area and highest parcel number, some of these I managed to do in dissolve tool, but that's not enough.

I know I can do it in ModelBuilder or step by step, and it may be easier for me. But unfortunately I HAVE TO do it as a Arcpy/Python code.

  • I suspect the subject of your first question should be how to split that IDENTYFIKA field into two fields for District and Parcel numbers. Then I think Summary Statistics will do the rest. – PolyGeo Sep 16 '16 at 11:17
3

If you're not confident with scripting, a simple way to do this is as follows:

  1. Add a field that will hold the district ID (format: string)
  2. Populate the field with the Calculate Field tool or the Field Calculator and this expression: !IDENTYFIKA![0:13] (Python parser).
  3. Use Add Geometry Attribute to add a field with the area of the parcels (this tool is new to ArcGIS 10.2, if you work with an older version, just add a field (format: double) and populate it with the following expression: !shape.area! (Python parser). If you work with a geodatabase feature class, you can use the shape.area field directly, but your input seems to be a shapefile.
  4. Dissolve the parcel features:
    • with the new district ID field as dissolve field parameter,
    • and use the statistic fields parameter to get the desired statistics (max value of parcel ID, average parcel area, etc).

These steps can be executed with ModelBuilder if you need to automate the process.

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.