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.
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.