Select to view content in your preferred language

split geometry at the antimeridian(i.e. international date line)

1113
2
Jump to solution
02-22-2022 10:53 AM
john_cartwright_noaa
New Contributor III

Hello All,

I'm using JSAPI 4.22 and have some simple polygons which cross the antimeridian and of course are not drawing correctly. I'm trying to split them and have tried two methods, neither of which have been successful.

1)  geometryEngine.cut() 

If the cut line is on meridian -180/180, an empty array of geometries is returned. It works as expected if using some other meridian.

2) normalizeUtils.normalizeCentralMeridian()

This only seems to split geometries that have longitude values > 180. For example, if the longitude values range from 179 to -179, the original geometry is returned unmodified.

Can anyone please explain what I'm missing or suggest an alternative?

Thanks!

--john

 

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
john_cartwright_noaa
New Contributor III

Thanks for your reply and suggestion Joel. I realized that the problem w/ geometryEngine.cut() is that when constructing a geometry that crosses the antimeridian, JSAPI is swapping the xmin and xmax values, essentially drawing the shape "the long way around" the globe and leaving a gap at the antimeridian where the shape was actually intended to cover. Using a variation on your suggestion, I offset all longitude values by 360 for shapes crossing the antimeridian. Then the JSAPI seems to correctly draw them on both SceneView and MapView. Neither the geometryEngine.cut() nor the normalizeUtils.normalizeCentralMeridian() methods are needed and in fact letting the JSAPI automatically handle the longitude values outside the -180/180 range prevents the split line from drawing.

 My use case are very simple shapes which I can identify as crossing the antimeridian so I don't know how robust the solution will be for general cases.

View solution in original post

0 Kudos
2 Replies
JoelBennett
MVP Regular Contributor

Regarding geometryEngine.cut, you say it works if using some other meridian.  It seems to me, then, that you could use geometryEngine.offset to move the geometry (e.g. 10 degrees west), then do the cut (e.g. on the 170 meridian), then offset the resultant geometries back (e.g. 10 degrees east).  If any resultant pieces are outside the -180 to 180 range, you could offset that piece further by 360 or -360 degrees (depending on which is appropriate for the situation).

0 Kudos
john_cartwright_noaa
New Contributor III

Thanks for your reply and suggestion Joel. I realized that the problem w/ geometryEngine.cut() is that when constructing a geometry that crosses the antimeridian, JSAPI is swapping the xmin and xmax values, essentially drawing the shape "the long way around" the globe and leaving a gap at the antimeridian where the shape was actually intended to cover. Using a variation on your suggestion, I offset all longitude values by 360 for shapes crossing the antimeridian. Then the JSAPI seems to correctly draw them on both SceneView and MapView. Neither the geometryEngine.cut() nor the normalizeUtils.normalizeCentralMeridian() methods are needed and in fact letting the JSAPI automatically handle the longitude values outside the -180/180 range prevents the split line from drawing.

 My use case are very simple shapes which I can identify as crossing the antimeridian so I don't know how robust the solution will be for general cases.

0 Kudos