<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Spacially Referencing a series of polygons in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/spacially-referencing-a-series-of-polygons/m-p/464098#M36369</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Xander Bakker,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess my main issue was in the line:&lt;/P&gt;&lt;P&gt;arcpy.Array([arcpy.Point(*coords) for coords in feature]),arcpy.SpatialReference(factoryCode)))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where factoryCode was an input Coordinate system from the user of this script. I was hoping to have the code so I can create the polygons with a different spatial without having to open the scrip everytime. Here is a better example of what I am triing to do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
arcpy.env.overwriteOutput = True 
inputWorkspace = arcpy.GetParameterAsText(0)
outputName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = arcpy.GetParameterAsText(1)
factoryCode&amp;nbsp;&amp;nbsp;&amp;nbsp; = arcpy.GetParameterAsText(2) #input Coordinate System
coordList = [[[1, 2], [2, 4], [3, 7]],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [[6, 8], [5, 7], [7, 2], [9, 5]]]

features = []
sr = arcpy.SpatialReference(factoryCode)
for feature in coordList:
features.append(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Polygon(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Array([arcpy.Point(*coords) for coords in feature]), sr))
arcpy.CopyFeatures_management(features, outputName)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 20:37:06 GMT</pubDate>
    <dc:creator>SheenaBerry</dc:creator>
    <dc:date>2021-12-11T20:37:06Z</dc:date>
    <item>
      <title>Spacially Referencing a series of polygons</title>
      <link>https://community.esri.com/t5/python-questions/spacially-referencing-a-series-of-polygons/m-p/464096#M36367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, I am working on a script that produces a polygon grid from a series of irregularly spaced points (hence why I can't use fishnet).&lt;/P&gt;&lt;P&gt;I have managed to produce the desired grid but am unable to assign a spactial reference to the grid.&lt;/P&gt;&lt;P&gt;I have tried a number of ways such as assigning a Spactial Reference. I've tried to assign it to the individual points using a for loop:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PointsList=[]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;for n in coordList:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array=[]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for coords in n:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; point=arcpy.Point(coords[0],coords[1])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ptGeometry=arcpy.PointGeometry(point,arcpy.SpatialReference(factoryCode))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array.append(ptGeometry)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PointsList.append(array)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;features = []&lt;/P&gt;&lt;P&gt;for feature in PointsList:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Create a Polygon object based on the array of points&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Append to the list of Polygon objects&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; features.append(&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Polygon(&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Array(*corner)) for corner in feature)&lt;/P&gt;&lt;P&gt;arcpy.CopyFeatures_management(features, outputName)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or to the polygon durring its construction:&lt;/P&gt;&lt;P&gt;features = []&lt;/P&gt;&lt;P&gt;for feature in coordList:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create a Polygon object based on the array of points&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Append to the list of Polygon objects&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; features.append(&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Polygon(&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Array([arcpy.Point(*coords) for coords in feature]), arcpy.SpatialReference(factoryCode)))&lt;/P&gt;&lt;P&gt;arcpy.CopyFeatures_management(features, outputName)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But both ways are giving me a runtime error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was wondering if it would be best to first create a feature class and then creat my polygons but I don't know how to write polygons to feature classes in python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If someone could provide guidance it would be much apprechiated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Mar 2015 16:45:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spacially-referencing-a-series-of-polygons/m-p/464096#M36367</guid>
      <dc:creator>SheenaBerry</dc:creator>
      <dc:date>2015-03-06T16:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Spacially Referencing a series of polygons</title>
      <link>https://community.esri.com/t5/python-questions/spacially-referencing-a-series-of-polygons/m-p/464097#M36368</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Below an extract from another post:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
arcpy.env.overwriteOutput = True
sr = arcpy.SpatialReference(4326) # WGS 1984

# coords
lon_min = 175
lon_max = 185
lat_min = 0
lat_max = 10

polygon = arcpy.Polygon(arcpy.Array([arcpy.Point(lon_min, lat_min),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Point(lon_min, lat_max),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Point(lon_max, lat_max),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Point(lon_max, lat_min),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Point(lon_min, lat_min)]),sr)

fc_out = r"D:\Xander\GeoNet\AroundTheWorld\polygon01.shp"
arcpy.CopyFeatures_management([polygon], fc_out)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notice that the Polygon is created from an Array of a list of Point objects.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your post I see you are using an "array"&amp;nbsp; which is in your case a list and you use PointGeometry objects.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:37:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spacially-referencing-a-series-of-polygons/m-p/464097#M36368</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-11T20:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Spacially Referencing a series of polygons</title>
      <link>https://community.esri.com/t5/python-questions/spacially-referencing-a-series-of-polygons/m-p/464098#M36369</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Xander Bakker,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess my main issue was in the line:&lt;/P&gt;&lt;P&gt;arcpy.Array([arcpy.Point(*coords) for coords in feature]),arcpy.SpatialReference(factoryCode)))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where factoryCode was an input Coordinate system from the user of this script. I was hoping to have the code so I can create the polygons with a different spatial without having to open the scrip everytime. Here is a better example of what I am triing to do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
arcpy.env.overwriteOutput = True 
inputWorkspace = arcpy.GetParameterAsText(0)
outputName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = arcpy.GetParameterAsText(1)
factoryCode&amp;nbsp;&amp;nbsp;&amp;nbsp; = arcpy.GetParameterAsText(2) #input Coordinate System
coordList = [[[1, 2], [2, 4], [3, 7]],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [[6, 8], [5, 7], [7, 2], [9, 5]]]

features = []
sr = arcpy.SpatialReference(factoryCode)
for feature in coordList:
features.append(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Polygon(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Array([arcpy.Point(*coords) for coords in feature]), sr))
arcpy.CopyFeatures_management(features, outputName)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:37:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spacially-referencing-a-series-of-polygons/m-p/464098#M36369</guid>
      <dc:creator>SheenaBerry</dc:creator>
      <dc:date>2021-12-11T20:37:06Z</dc:date>
    </item>
  </channel>
</rss>

