Sunday, 2 June 2013

Shape to Points from GIS.StackExchange

Oldies but goodies:
Shape to points posted on GIS.Stackexchange

http://gis.stackexchange.com/questions/19106/resolving-arcpy-getobject-not-point-error

 
If you want to use a function to be called, then you can look at this example.

def pntXY(pnt):
  '''Gets X,Y coordinates given a point object, returns a list'''
  XY= [pnt.X, pnt.Y]
  return XY

def shapeToPoints(a_shape,theType,arcpy):
  '''
  pnts = shapeToPoints(a_shape, shape type, geoprocessor)
  Purpose:  Converts a shape to points, the shape and its type
  are passed by the calling script
  Requires:  def pntXY(pnt)
  '''
  outList=[]
  part_num = 0
  part_count = a_shape.partCount
  if theType == "Multipoint":    #Multipoints
    while part_num < part_count:
      pnt = a_shape.getPart(part_num)
      XY = pntXY(pnt)
      if XY not in outList:
        outList.append(XY)
      part_num += 1
  else:                          #Poly* features
    while part_num < part_count: #cycle through the parts
      a_part = a_shape.getPart(part_num)
      pnt = a_part.next()
      while pnt:                 #cycle through the points
        XY = pntXY(pnt)
        if XY not in outList:
          outList.append(XY)
        pnt = a_part.next()      
        if not pnt:              #null point check (rings/donuts)
          pnt = a_part.next()
          if pnt:
         XY = pntXY(pnt)
         if XY not in outList:
           outList.append(XY)
    part_num += 1
  return outList

No comments:

Post a Comment