How do I create polygons crossing 0 Longitude in the Pacific

4300
5
Jump to solution
03-03-2015 11:41 AM
KarenMaloof1
New Contributor

I'm working with a txt file with a bunch of N, W, E and W extents, and turning them into polygons. Two of them are in the Pacific, crossing 0 Longitude, and when I try to create the polygon, it makes a very long polygon going the opposite direction around the world, rather than cross 0. How can I get the polygon to cross 0, while letting the script still work properly on the rest of the world?

Thanks,

Karen

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

If you have 0 longitud the point will be located at Greenwhich longitude and not in the Pacific. Do you have longitudes near +180 and -180?

If I use the following code:

def main():
    import arcview
    import arcpy
    arcpy.env.overwriteOutput = True
    sr = arcpy.SpatialReference(4326) # WGS 1984

    # 01
    lon_min = 175
    lon_max = 185
    lat_min = 0
    lat_max = 10

    polygon = arcpy.Polygon(arcpy.Array([arcpy.Point(lon_min, lat_min),
                                        arcpy.Point(lon_min, lat_max),
                                        arcpy.Point(lon_max, lat_max),
                                        arcpy.Point(lon_max, lat_min),
                                        arcpy.Point(lon_min, lat_min)]),sr)

    fc_out = r"D:\Xander\GeoNet\AroundTheWorld\polygon01.shp"
    arcpy.CopyFeatures_management([polygon], fc_out)


    # 02
    lon_min = 175
    lon_max = -175
    lat_min = -10
    lat_max = 0

    polygon = arcpy.Polygon(arcpy.Array([arcpy.Point(lon_min, lat_min),
                                        arcpy.Point(lon_min, lat_max),
                                        arcpy.Point(lon_max, lat_max),
                                        arcpy.Point(lon_max, lat_min),
                                        arcpy.Point(lon_min, lat_min)]),sr)

    fc_out = r"D:\Xander\GeoNet\AroundTheWorld\polygon02.shp"
    arcpy.CopyFeatures_management([polygon], fc_out)

if __name__ == '__main__':
    main()

I get this:

AroundTheWorld.png

Polygon 02 travels all around the world, while Polygon 01 crosses the date border since I used 185, instead of -175.

View solution in original post

5 Replies
JoeBorgione
MVP Emeritus

0 longitude in the Pacific?  I know it's been a while since I was in school, but I was under the impression that 0 Longitude is the prime meridian: Zulu: Greenwich (England)....  Perhaps you mean 180 or -180?

That should just about do it....
0 Kudos
KarenMaloof1
New Contributor

Yes, I did mean 180.

0 Kudos
XanderBakker
Esri Esteemed Contributor

If you have 0 longitud the point will be located at Greenwhich longitude and not in the Pacific. Do you have longitudes near +180 and -180?

If I use the following code:

def main():
    import arcview
    import arcpy
    arcpy.env.overwriteOutput = True
    sr = arcpy.SpatialReference(4326) # WGS 1984

    # 01
    lon_min = 175
    lon_max = 185
    lat_min = 0
    lat_max = 10

    polygon = arcpy.Polygon(arcpy.Array([arcpy.Point(lon_min, lat_min),
                                        arcpy.Point(lon_min, lat_max),
                                        arcpy.Point(lon_max, lat_max),
                                        arcpy.Point(lon_max, lat_min),
                                        arcpy.Point(lon_min, lat_min)]),sr)

    fc_out = r"D:\Xander\GeoNet\AroundTheWorld\polygon01.shp"
    arcpy.CopyFeatures_management([polygon], fc_out)


    # 02
    lon_min = 175
    lon_max = -175
    lat_min = -10
    lat_max = 0

    polygon = arcpy.Polygon(arcpy.Array([arcpy.Point(lon_min, lat_min),
                                        arcpy.Point(lon_min, lat_max),
                                        arcpy.Point(lon_max, lat_max),
                                        arcpy.Point(lon_max, lat_min),
                                        arcpy.Point(lon_min, lat_min)]),sr)

    fc_out = r"D:\Xander\GeoNet\AroundTheWorld\polygon02.shp"
    arcpy.CopyFeatures_management([polygon], fc_out)

if __name__ == '__main__':
    main()

I get this:

AroundTheWorld.png

Polygon 02 travels all around the world, while Polygon 01 crosses the date border since I used 185, instead of -175.

KarenMaloof1
New Contributor

Thanks, that helped.

0 Kudos
BruceHarold
Esri Regular Contributor

Hi

As Xander more or less pointed out, 0-360 longitudes can be used to create GCS coordinates but any time you geoprocess the features they will be split into multipart across the 180.  If you need to work with single part features then project to a suitable  local coordinate system.

Regards