Skip to main content
added 310 characters in body
Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 188

A bit unclear what you want but you should be able to use collections.defaultdict:

Using list as the default_factory, it is easy to group a sequence of key-value pairs into a dictionary of lists

import arcpy
from collections import defaultdict
fc = r"C:\folder\shapefile.shp"
dx = defaultdict(list)
dy = defaultdict(list)

with arcpy.da.SearchCursor(fc,['OID@','SHAPE@']) as cursor:
    for row in cursor:
        array1=row[1].getPart()
        for vertice in range(row[1].pointCount):
            pnt=array1.getObject(0).getObject(vertice)
            dx[row[0]].append(pnt.X)
            dy[row[0]].append(pnt.Y)

You will now have two dictionaries with ObjectID as key and a list of coordinates for each polygon as values . For example all the vertices for the first polygon (objectid 0) as lists:

print(dx[0])
print(dy[0])
>>[800000.0, 800000.0, 700000.0, 700000.0, 800000.0]
>>[7400000.0, 7300000.0, 7300000.0, 7400000.0, 7400000.0]

Start and end coordinates are the same. Can be removed if you want.

Iterating:

for oid in dx:
    print(dx[oid], dy[oid])
>>[800000.0, 800000.0, 700000.0, 700000.0, 800000.0] [7400000.0, 7300000.0, 7300000.0, 7400000.0, 7400000.0]
>>[800000.0, 800000.0, 700000.0, 700000.0, 800000.0] [7400000.0, 7300000.0, 7300000.0, 7400000.0, 7400000.0]
>>...

A bit unclear what you want but you should be able to use collections.defaultdict:

Using list as the default_factory, it is easy to group a sequence of key-value pairs into a dictionary of lists

import arcpy
from collections import defaultdict
fc = r"C:\folder\shapefile.shp"
dx = defaultdict(list)
dy = defaultdict(list)

with arcpy.da.SearchCursor(fc,['OID@','SHAPE@']) as cursor:
    for row in cursor:
        array1=row[1].getPart()
        for vertice in range(row[1].pointCount):
            pnt=array1.getObject(0).getObject(vertice)
            dx[row[0]].append(pnt.X)
            dy[row[0]].append(pnt.Y)

You will now have two dictionaries with ObjectID as key and a list of coordinates for each polygon as values . For example all the vertices for the first polygon (objectid 0) as lists:

print(dx[0])
print(dy[0])
>>[800000.0, 800000.0, 700000.0, 700000.0, 800000.0]
>>[7400000.0, 7300000.0, 7300000.0, 7400000.0, 7400000.0]

Start and end coordinates are the same. Can be removed if you want.

A bit unclear what you want but you should be able to use collections.defaultdict:

Using list as the default_factory, it is easy to group a sequence of key-value pairs into a dictionary of lists

import arcpy
from collections import defaultdict
fc = r"C:\folder\shapefile.shp"
dx = defaultdict(list)
dy = defaultdict(list)

with arcpy.da.SearchCursor(fc,['OID@','SHAPE@']) as cursor:
    for row in cursor:
        array1=row[1].getPart()
        for vertice in range(row[1].pointCount):
            pnt=array1.getObject(0).getObject(vertice)
            dx[row[0]].append(pnt.X)
            dy[row[0]].append(pnt.Y)

You will now have two dictionaries with ObjectID as key and a list of coordinates for each polygon as values . For example all the vertices for the first polygon (objectid 0) as lists:

print(dx[0])
print(dy[0])
>>[800000.0, 800000.0, 700000.0, 700000.0, 800000.0]
>>[7400000.0, 7300000.0, 7300000.0, 7400000.0, 7400000.0]

Start and end coordinates are the same. Can be removed if you want.

Iterating:

for oid in dx:
    print(dx[oid], dy[oid])
>>[800000.0, 800000.0, 700000.0, 700000.0, 800000.0] [7400000.0, 7300000.0, 7300000.0, 7400000.0, 7400000.0]
>>[800000.0, 800000.0, 700000.0, 700000.0, 800000.0] [7400000.0, 7300000.0, 7300000.0, 7400000.0, 7400000.0]
>>...
added 30 characters in body
Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 188

A bit unclear what you want but you should be able to use collections.defaultdict:

Using list as the default_factory, it is easy to group a sequence of key-value pairs into a dictionary of lists

import arcpy
from collections import defaultdict
fc = r"C:\folder\shapefile.shp"
dx = defaultdict(list)
dy = defaultdict(list)

with arcpy.da.SearchCursor(fc,['OID@','SHAPE@']) as cursor:
    for row in cursor:
        array1=row[1].getPart()
        for vertice in range(row[1].pointCount):
            pnt=array1.getObject(0).getObject(vertice)
            dx[row[0]].append(pnt.X)
            dy[row[0]].append(pnt.Y)

You will now have two dictionaries with all x and y values and ObjectID as keyskey and a list of coordinates for each polygon as values . For example all the vertices for the first polygon (objectid 0) as lists:

print(dx[0])
print(dy[0])
>>[800000.0, 800000.0, 700000.0, 700000.0, 800000.0]
>>[7400000.0, 7300000.0, 7300000.0, 7400000.0, 7400000.0]

Start and end coordinates are the same. Can be removed if you want.

A bit unclear what you want but you should be able to use collections.defaultdict:

Using list as the default_factory, it is easy to group a sequence of key-value pairs into a dictionary of lists

import arcpy
from collections import defaultdict
fc = r"C:\folder\shapefile.shp"
dx = defaultdict(list)
dy = defaultdict(list)

with arcpy.da.SearchCursor(fc,['OID@','SHAPE@']) as cursor:
    for row in cursor:
        array1=row[1].getPart()
        for vertice in range(row[1].pointCount):
            pnt=array1.getObject(0).getObject(vertice)
            dx[row[0]].append(pnt.X)
            dy[row[0]].append(pnt.Y)

You will now have two dictionaries with all x and y values and ObjectID as keys. For example all the vertices for the first polygon (objectid 0) as lists:

print(dx[0])
print(dy[0])
>>[800000.0, 800000.0, 700000.0, 700000.0, 800000.0]
>>[7400000.0, 7300000.0, 7300000.0, 7400000.0, 7400000.0]

Start and end coordinates are the same. Can be removed if you want.

A bit unclear what you want but you should be able to use collections.defaultdict:

Using list as the default_factory, it is easy to group a sequence of key-value pairs into a dictionary of lists

import arcpy
from collections import defaultdict
fc = r"C:\folder\shapefile.shp"
dx = defaultdict(list)
dy = defaultdict(list)

with arcpy.da.SearchCursor(fc,['OID@','SHAPE@']) as cursor:
    for row in cursor:
        array1=row[1].getPart()
        for vertice in range(row[1].pointCount):
            pnt=array1.getObject(0).getObject(vertice)
            dx[row[0]].append(pnt.X)
            dy[row[0]].append(pnt.Y)

You will now have two dictionaries with ObjectID as key and a list of coordinates for each polygon as values . For example all the vertices for the first polygon (objectid 0) as lists:

print(dx[0])
print(dy[0])
>>[800000.0, 800000.0, 700000.0, 700000.0, 800000.0]
>>[7400000.0, 7300000.0, 7300000.0, 7400000.0, 7400000.0]

Start and end coordinates are the same. Can be removed if you want.

added 534 characters in body
Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 188

To create two lists holding x- and y coordinatesA bit unclear what you want but you should be able to use collections.defaultdict:

Using list as the default_factory, it is easy to group a sequence of key-value pairs into a dictionary of lists

import arcpy
from collections import defaultdict
fc = r'Cr"C:\folder\shapefile.shp'
shp"
xcoordsdx = []defaultdict(list)
ycoordsdy = []defaultdict(list)

with arcpy.da.SearchCursor(fc,['OID@','SHAPE@']) as cursor:
    for row in cursor:
        array1=row[1].getPart()
        for vertice in range(row[1].pointCount):
            pnt=array1.getObject(0).getObject(vertice)
            xcoordsdx[row[0]].append(pnt.X)
            ycoordsdy[row[0]].append(pnt.Y)
       

You will now have two dictionaries with all x and y values and ObjectID as keys. For example all the vertices for the first polygon (objectid 0) as lists:

print(dx[0])
print(dy[0])
>>[800000.0, 800000.0, 700000.0, 700000.0, 800000.0]
>>[7400000.0, #Do7300000.0, something7300000.0, with7400000.0, objectid/row[0]7400000.0]

Start and end coordinates are the same. Can be removed if you want.

To create two lists holding x- and y coordinates:

import arcpy
fc = r'C:\folder\shapefile.shp'

xcoords = []
ycoords = []

with arcpy.da.SearchCursor(fc,['OID@','SHAPE@']) as cursor:
    for row in cursor:
        array1=row[1].getPart()
        for vertice in range(row[1].pointCount):
            pnt=array1.getObject(0).getObject(vertice)
            xcoords.append(pnt.X)
            ycoords.append(pnt.Y)
            #Do something with objectid/row[0]

A bit unclear what you want but you should be able to use collections.defaultdict:

Using list as the default_factory, it is easy to group a sequence of key-value pairs into a dictionary of lists

import arcpy
from collections import defaultdict
fc = r"C:\folder\shapefile.shp"
dx = defaultdict(list)
dy = defaultdict(list)

with arcpy.da.SearchCursor(fc,['OID@','SHAPE@']) as cursor:
    for row in cursor:
        array1=row[1].getPart()
        for vertice in range(row[1].pointCount):
            pnt=array1.getObject(0).getObject(vertice)
            dx[row[0]].append(pnt.X)
            dy[row[0]].append(pnt.Y)

You will now have two dictionaries with all x and y values and ObjectID as keys. For example all the vertices for the first polygon (objectid 0) as lists:

print(dx[0])
print(dy[0])
>>[800000.0, 800000.0, 700000.0, 700000.0, 800000.0]
>>[7400000.0, 7300000.0, 7300000.0, 7400000.0, 7400000.0]

Start and end coordinates are the same. Can be removed if you want.

Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 188
Loading