AnsweredAssumed Answered

Why is the creation of the arcpy.Polygon object failing for this point array?

Question asked by kuiperfoliage on Jan 27, 2016
Latest reply on Jan 28, 2016 by GSCUser85

Hi,

 

I have developed two tests to demonstrate the problem

 

    def test_centroidTestFails(self):

        polygonpoints = [

         [37.310437, -122.244706],

         [37.320437, -122.244706],

         [37.320437, -122.242706],

         [37.310437, -122.242706]]

 

 

        points = arcpy.Array([arcpy.Point(*coords) for coords in polygonpoints])

        polygon = arcpy.Polygon(points)

        with self.assertRaises(Exception) as context:

            centroid = polygon.centroid

 

 

    def test_centroidTestSucceeds(self):

        polygonpoints = [

         [37.310437, -122.244706],

         [37.320437, -122.244706],

         [37.320437, -122.241706],

         [37.310437, -122.241706]]

 

 

        points = arcpy.Array([arcpy.Point(*coords) for coords in polygonpoints])

        polygon = arcpy.Polygon(points)

        centroid = polygon.centroid

 

Why is the first test failing? For some reason the generated points array can't be used as input for the arcpy.Polygon() constructor. polygon.pointCount will return 0 for the test_centroidTestFails(). What is going wrong? Am i doing something wrong or is this a framework problem?

 

EDIT:  Note that there is a small difference in the data points that are used for the two tests. The first test fails for no apparent reason and polygon.pointCount will return 0 on this test. The second test works successfully. For some reason the Array of points that is created is not accepted by the polygon constructor in the first test. Adding an additional point to close the polygon is not necessary and doesn't resolve the issue. The polygon will still return 0 points when using the data points from the first test.

 

EDIT 2: the minor difference is -122.242706 vs. -122.241706 for the last two data points. ( .242 vs .241)

Outcomes