2

I am creating polygons from a text file and am having trouble with the polygons crossing the 180 degree line. The issue is creating rectangular polygons with a sliver cut out of it as seen here:

enter image description here

I am trying to put this into a KML and it is only reading the first portion before the sliver due to it being a multipart polygon (which is probably caused by the sliver).

Now I want to cover the exact area the rectangle covers (therefore, using something like the Minimum Bounding Geometry tool wouldn't be the best). Is there a way to fill in this sliver, essentially tracing the exact boundary of the polygon shapefile?

An example of the text file I use to create the polygon are:

Polygon
5000132132313 0
0 -174.827514 53.178572
1 -174.036917 55.064749
2 -173.186155 56.947081
3 -172.264216 58.824950
4 -171.257368 60.697589
5 -170.148276 62.564020
6 -168.914757 64.422986
7 -167.527996 66.272836
8 -165.949956 68.111373
9 -164.129507 69.935602
10 -161.996584 71.741355
11 -159.453151 73.522684
12 -156.359068 75.270853
13 -152.509946 76.972637
14 -147.603415 78.607367
15 -141.193251 80.141761
16 -165.088765 82.151769
17 -168.457544 80.306807
18 -170.829765 78.442363
19 -172.615466 76.566459
20 -174.028458 74.683216
21 -175.190541 72.794957
22 -176.175996 70.903081
23 -177.032631 69.008480
24 -177.792589 67.111748
25 -178.478274 65.213293
26 -179.105779 63.313405
27 -179.686970 61.412295
28 179.769207 59.510125
29 179.255875 57.607015
30 178.767649 55.703063
31 178.300251 53.798348
32 177.850232 51.892936
33 177.677041 51.141937
34 -175.845800 50.543655
35 -175.566878 51.289044
36-174.827514 53.178572
END

The tool used with this syntax is "Create Features from Text File (Samples)". Areas not crossing the 180 work perfectly, so the vertices are doing something strange when ran across the 180.

  • Can you provide an example of your text file data, as well as your method of creating the polygons from the data? – Emil Brundage Nov 20 '15 at 0:31
  • I have added an example of what I did – Will Nov 20 '15 at 0:43
  • MBG will "fill in" your missing gap... unless I'm missing something about your data. – Paul Nov 20 '15 at 1:32
  • Yes, minimum boundary would work, but it wouldn't fit exactly to my polygon. Since my polygon slightly curves instead of being straight, the boundary file would end up extended a bit on all sides to take into effect the curve. I don't have an advanced license so I can't test the multiple geometry types within the parameters. – Will Nov 20 '15 at 1:39
  • Nice work Emil. Is it just a coincidence that the text you posted is missing a space between the line number and the coordinates on line 36? Could be why your poly is not closing. 36-174.827514 53.178572 – Ben S Nadler Nov 20 '15 at 18:07
1

Here's some code that should work with your text file. You'll need to update the first three variables (textFl, outPath, outName). The script creates a new feature class, and then iterates through the text file and looks for lines with coordinates. It adds those coordinates to a list until a line doesn't have coordinates. It then creates a polygon feature from the list of coordinates and adds it to the new feature class.

#text file
textFl = r"C:\GIS_Stackexchange\test.txt"

#output geodatabase location
outPath = r"C:\Workspace\Workspace.gdb"
#output feature class name
outName = "output"

import arcpy

def CreateFeature (updateFc, pointList):
    #empty array to store points
    array = arcpy.Array ()
    #point object
    point = arcpy.Point ()
    #iterate xys
    for xy in pointList:
        #update point geometry
        point.X = xy [0]
        point.Y = xy [1]
        array.add(point)

    #add first point to close polygon
    #not necessary for example you provided, but doesn't hurt 
    array.add (array.getObject (0)) 

    #convert points array to polygon geometry
    geom = arcpy.Geometry ("POLYGON", array)

    #insert cursor
    with arcpy.da.InsertCursor (updateFc, "SHAPE@") as cursor:
        row = (geom,)
        cursor.insertRow (row)
    del cursor



#create spatial reference
sr = arcpy.SpatialReference ("WGS 1984")

#create feature class
print "creating new feature class", outName
fc = arcpy.CreateFeatureclass_management (outPath,
                                          outName,
                                          "POLYGON",
                                          spatial_reference
                                          = sr).getOutput (0)

#empty list to populate points
points = []

#iteate lines in text file
print "reading text file"
with open (textFl, "r") as f:
    for line in f:

        #skip blank lines
        if not line:
            continue

        #split line at space
        vals = line.split (" ")

        #lines without three values aren't coordinates
        if len (vals) != 3:

            #check if points list has points
            if points:
                CreateFeature (fc, points)
                #reset points list
                points = []

        #otherwise line values are coordinates
        else:
            #add coordinates as tuple to points list
            points += [(float (vals[1]), float (vals[2]))]

f.close ()
print "done"
  • Thanks for the code, I knew that took you some time! I have already run thousands upon thousands of records like the example provided, so I wouldn't want to replot all those polygons. I was hoping there would be a way to simply close off the sliver that exists. If I need to, I will study from your code, so thank you. – Will Nov 20 '15 at 2:09
0

Yes it is about crossing time line. The points when connected as they are result in self intersecting closed line. As a result - multipart polygon or 2 polygons when I used build polygons from advanced editing.

The only option I can see is to project points first and to use them to built polygon. Picture below shows points from sample and polygon, projection North_Pole_Azimuthal_Equidistant

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.