Python arcpy.Polygon() Examples

The following are 7 code examples of arcpy.Polygon(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module arcpy , or try the search function .
Example #1
Source File: section_cpu.py    From HiSpatialCluster with Apache License 2.0 10 votes vote down vote up
def generate_cls_boundary(cls_input,cntr_id_field,boundary_output,cpu_core):
    arcpy.env.parallelProcessingFactor=cpu_core
    arcpy.SetProgressorLabel('Generating Delaunay Triangle...')
    arrays=arcpy.da.FeatureClassToNumPyArray(cls_input,['SHAPE@XY',cntr_id_field])
   
    cid_field_type=[f.type for f in arcpy.Describe(cls_input).fields if f.name==cntr_id_field][0]
    delaunay=Delaunay(arrays['SHAPE@XY']).simplices.copy()
    arcpy.CreateFeatureclass_management('in_memory','boundary_temp','POLYGON',spatial_reference=arcpy.Describe(cls_input).spatialReference)
    fc=r'in_memory\boundary_temp'
    arcpy.AddField_management(fc,cntr_id_field,cid_field_type)
    cursor = arcpy.da.InsertCursor(fc, [cntr_id_field,"SHAPE@"])
    arcpy.SetProgressor("step", "Copying Delaunay Triangle to Temp Layer...",0, delaunay.shape[0], 1)
    for tri in delaunay:
        arcpy.SetProgressorPosition()
        cid=arrays[cntr_id_field][tri[0]]
        if cid == arrays[cntr_id_field][tri[1]] and cid == arrays[cntr_id_field][tri[2]]:
            cursor.insertRow([cid,arcpy.Polygon(arcpy.Array([arcpy.Point(*arrays['SHAPE@XY'][i]) for i in tri]))])
    arcpy.SetProgressor('default','Merging Delaunay Triangle...')
    if '64 bit' in sys.version:
        arcpy.PairwiseDissolve_analysis(fc,boundary_output,cntr_id_field)
    else:
        arcpy.Dissolve_management(fc,boundary_output,cntr_id_field)
    arcpy.Delete_management(fc)
    
    return 
Example #2
Source File: arcapi.py    From arcapi with GNU Lesser General Public License v3.0 6 votes vote down vote up
def make_poly_from_extent(ext, sr):
    """Make an arcpy polygon object from an input extent object.,Returns
    a polygon geometry object.

    Required:
    ext -- extent object
    sr -- spatial reference

    Example
    >>> ext = arcpy.Describe(fc).extent
    >>> sr = 4326  #WKID for WGS 84
    >>> poly = make_poly_from_extent(ext, sr)
    >>> arcpy.CopyFeatures_management(poly, r'C:\Temp\Project_boundary.shp')
    """
    array = arcpy.Array()
    array.add(ext.lowerLeft)
    array.add(ext.lowerRight)
    array.add(ext.upperRight)
    array.add(ext.upperLeft)
    array.add(ext.lowerLeft)
    return arcpy.Polygon(array, sr) 
Example #3
Source File: filters.py    From ArcREST with Apache License 2.0 5 votes vote down vote up
def geometry(self, geometry):
        """ sets the geometry value """
     
        if isinstance(geometry, AbstractGeometry):
            self._geomObject = geometry
            self._geomType = geometry.type
        elif arcpyFound :
            wkid = None
            wkt = None
            if (hasattr(geometry, 'spatialReference') and \
                       geometry.spatialReference is not None):
                if (hasattr(geometry.spatialReference, 'factoryCode') and \
                            geometry.spatialReference.factoryCode is not None):
                    wkid = geometry.spatialReference.factoryCode
                else:
                    wkt = geometry.spatialReference.exportToString()
                    
            if isinstance(geometry, arcpy.Polygon):
                
                self._geomObject = Polygon(geometry, wkid=wkid, wkt=wkt)
                self._geomType = "esriGeometryPolygon"
            elif isinstance(geometry, arcpy.Point):
                self._geomObject = Point(geometry, wkid=wkid, wkt=wkt)
                self._geomType = "esriGeometryPoint"
            elif isinstance(geometry, arcpy.Polyline):
                self._geomObject = Polyline(geometry, wkid=wkid, wkt=wkt)
                self._geomType = "esriGeometryPolyline"
            elif isinstance(geometry, arcpy.Multipoint):
                self._geomObject = MultiPoint(geometry, wkid=wkid, wkt=wkt)
                self._geomType = "esriGeometryMultipoint"
            else:
                raise AttributeError("geometry must be a common.Geometry or arcpy.Geometry type.")
        else:
            raise AttributeError("geometry must be a common.Geometry or arcpy.Geometry type.")        
    #---------------------------------------------------------------------- 
Example #4
Source File: geometry.py    From ArcREST with Apache License 2.0 5 votes vote down vote up
def __geomToPointList(self, geom):
        """ converts a geometry object to a common.Geometry object """
        sr = geom.spatialReference
        wkid = None
        wkt = None
        if sr is None:
            if self._wkid is None and self._wkt is not None:
                wkt = self._wkt
            else:
                wkid = self._wkid
        else:
            wkid = sr.factoryCode
        g = json.loads(geom.JSON)
        top = []
        for gring in g['rings']:
            ring = []
            for g in gring:
                ring.append(Point(coord=g, wkid=wkid, wkt=wkt, z=None, m=None))
            top.append(ring)
        return top
        #if isinstance(geom, arcpy.Polygon):
            #feature_geom = []
            #fPart = []
            #for part in geom:
                #fPart = []
                #for pnt in part:
                    #if geom.spatialReference is None:
                        #wkid = self._wkid
                    #else:
                        #wkid = geom.spatialReference.factoryCode
                    #fPart.append(Point(coord=[pnt.X, pnt.Y],
                          #wkid=wkid,
                          #z=pnt.Z, m=pnt.M))
                #feature_geom.append(fPart)
            #return feature_geom
    #---------------------------------------------------------------------- 
Example #5
Source File: geometry.py    From ArcREST with Apache License 2.0 5 votes vote down vote up
def asArcPyObject(self):
        """ returns the Envelope as an ESRI arcpy.Polygon object """
        env = self.asDictionary
        ring = [[
            Point(env['xmin'], env['ymin'], self._wkid),
            Point(env['xmax'], env['ymin'], self._wkid),
            Point(env['xmax'], env['ymax'], self._wkid),
            Point(env['xmin'], env['ymax'], self._wkid)
            ]]
        return Polygon(rings=ring,
                       wkid=self._wkid,
                       wkt=self._wkid,
                       hasZ=False,
                       hasM=False).asArcPyObject 
Example #6
Source File: datasetExtentToFeatures.py    From sample-gp-tools with Apache License 2.0 5 votes vote down vote up
def execute(in_datasets, out_fc):
    # use gcs as output sr since all extents will fit in it
    out_sr = arcpy.SpatialReference("WGS 1984")

    in_datasets = in_datasets.split(";")

    arcpy.CreateFeatureclass_management(os.path.dirname(out_fc),
                                        os.path.basename(out_fc),
                                        "POLYGON",
                                        spatial_reference=out_sr)

    arcpy.AddField_management(out_fc, "dataset", "TEXT", 400)

    # add each dataset's extent & the dataset's name to the output
    with arcpy.da.InsertCursor(out_fc, ("SHAPE@", "dataset")) as cur:

        for i in in_datasets:
            d = arcpy.Describe(i)
            ex = d.Extent
            pts = arcpy.Array([arcpy.Point(ex.XMin, ex.YMin),
                              arcpy.Point(ex.XMin, ex.YMax),
                              arcpy.Point(ex.XMax, ex.YMax),
                              arcpy.Point(ex.XMax, ex.YMin),
                              arcpy.Point(ex.XMin, ex.YMin),])

            geom = arcpy.Polygon(pts,  d.SpatialReference)

            if d.SpatialReference != out_sr:
                geom = geom.projectAs(out_sr)
            cur.insertRow([geom, d.CatalogPath]) 
Example #7
Source File: arc_restapi.py    From restapi with GNU General Public License v2.0 5 votes vote down vote up
def asShape(self):
        """Returns JSON as arcpy.Geometry() object."""
        if self.geometryType != ESRI_ENVELOPE:
            return arcpy.AsShape(self.json, True)
        else:
            ar = arcpy.Array([
                arcpy.Point(self.json[XMIN], self.json[YMAX]),
                arcpy.Point(self.json[XMAX], self.json[YMAX]),
                arcpy.Point(self.json[XMAX], self.json[YMIN]),
                arcpy.Point(self.json[XMIN], self.json[YMIN])
            ])
            return arcpy.Polygon(ar, arcpy.SpatialReference(self.spatialReference))