Select to view content in your preferred language

Points to a list

715
4
08-23-2010 12:47 PM
RandalHale
Occasional Contributor
I've been looking for an example of how to do this - in all of my attempts I have fallen short. This deals more with python most likely than ArcGIS.

I've got to develop a polygon (actually a "hull") for a client running Arcview 10. I've geocoded addresses and now need to grab information "within" those points (polygons that exist within the point cloud). I thought I had solved this problem with 10 - until I realized the hull tool only existed in ArcINFO - not arcview. All other examples have been 9.3.1 related.....

If I follow the example from reading geometries:

import arcpy

infc = "Points_to_a_shapefiles"

# Identify the geometry field
#
desc = arcpy.Describe(infc)
shapefieldname = desc.ShapeFieldName

# Create search cursor
#
rows = arcpy.SearchCursor(infc)

# Enter for loop for each feature/row
#
for row in rows:
    # Create the geometry object 'feat'
    #
    feat = row.getValue(shapefieldname)
    pnt = feat.getPart()

    # Print x,y coordinates of current point
    #
    print pnt.X, pnt.Y


How would I toss x and y into a list that I could access.....it seems like everything I've tried doesn't work entirely. Plus it's been a day of distraction.....

Actually I hope someone looks at this and goes "Oh - you do this like <blank>" - I can't be the first one trying to invent this wheel.

Many thanks hopefully....
0 Kudos
4 Replies
JasonScheirer
Esri Alum
You can do pnt.__geo_interface__ to get a GeoJson representation, the "coordinates" attribute of the dictionary is what you need. You can use AsShape to go the other direction.
0 Kudos
RandalHale
Occasional Contributor
I appreciate the answer but for the slow - of which I am today -  Can you give me a small example - I've heard Geojson twice now in less than a week and I'm a bit unclear on what it is (hastily reading on the net and ESRI Docs now)
0 Kudos
JasonScheirer
Esri Alum
In this context, it's a Python dictionary of a specific form that, from what I can tell, has the data you're going for already in a convenient format.
0 Kudos
BruceHarold
Esri Regular Contributor
Hi

Another approach might be a list comprehension:

ptTupleList = [(p.shape.firstPoint.X,p.shape.firstPoint.Y) for p in arcpy.SearchCursor(myFC)]

...will give you a list of (X,Y) tuples.

Also, please keep an eye on the GP gallery, there is a hull tool in the works for footprints of address points.  It may be out in September.

Regards
0 Kudos