Comparison with WRAPDATELINE¶
GDAL has the WRAPDATELINE
option to deal with geometries that cross the antimeridian, which was added to ogr2ogr
in v1.7.0 via the -wrapdateline
flag.
As demonstrated below, antimeridian
has more-or-less the same behavior but includes a couple of modifications and improvements:
antimeridian
outputs the same geometry type as the input.ogr2ogr
outputs aFeatureCollection
.ogr2ogr
requires tuning via the-datelineoffset
flag. To get corrected outputs fromogr2ogr
, we had to set the-datelineoffset
to180
(the default is10
).antimeridian
handles the poles (usually).
In [ ]:
Copied!
import json
import subprocess
import shapely.geometry
from cartopy.crs import PlateCarree
from matplotlib import pyplot
def plot(name: str) -> None:
path = f"../tests/data/input/{name}.json"
antimeridian_output = shapely.geometry.shape(
json.loads(subprocess.check_output(["antimeridian", "fix", path]))
)
ogr2ogr_feature_collection = json.loads(
subprocess.check_output(
[
"ogr2ogr",
"-q",
"-f",
"GeoJSON",
"-wrapdateline",
"-datelineoffset",
"180",
"/vsistdout/",
path,
],
)
)
assert len(ogr2ogr_feature_collection["features"]) == 1
ogr2ogr_output = shapely.geometry.shape(
ogr2ogr_feature_collection["features"][0]["geometry"]
)
figure = pyplot.figure()
axes = figure.add_subplot(121, projection=PlateCarree())
axes.set_title(f"{name} (antimeridian)")
axes.stock_img()
axes.coastlines()
axes.add_geometries(
antimeridian_output, crs=PlateCarree(), color="coral", alpha=0.7
)
axes = figure.add_subplot(122, projection=PlateCarree())
axes.set_title(f"{name} (ogr2ogr)")
axes.stock_img()
axes.coastlines()
axes.add_geometries(ogr2ogr_output, crs=PlateCarree(), color="coral", alpha=0.7)
for name in [
"split",
"multi-split",
"complex-split",
"two-holes",
"line",
"issues-124",
]:
plot(name)
import json
import subprocess
import shapely.geometry
from cartopy.crs import PlateCarree
from matplotlib import pyplot
def plot(name: str) -> None:
path = f"../tests/data/input/{name}.json"
antimeridian_output = shapely.geometry.shape(
json.loads(subprocess.check_output(["antimeridian", "fix", path]))
)
ogr2ogr_feature_collection = json.loads(
subprocess.check_output(
[
"ogr2ogr",
"-q",
"-f",
"GeoJSON",
"-wrapdateline",
"-datelineoffset",
"180",
"/vsistdout/",
path,
],
)
)
assert len(ogr2ogr_feature_collection["features"]) == 1
ogr2ogr_output = shapely.geometry.shape(
ogr2ogr_feature_collection["features"][0]["geometry"]
)
figure = pyplot.figure()
axes = figure.add_subplot(121, projection=PlateCarree())
axes.set_title(f"{name} (antimeridian)")
axes.stock_img()
axes.coastlines()
axes.add_geometries(
antimeridian_output, crs=PlateCarree(), color="coral", alpha=0.7
)
axes = figure.add_subplot(122, projection=PlateCarree())
axes.set_title(f"{name} (ogr2ogr)")
axes.stock_img()
axes.coastlines()
axes.add_geometries(ogr2ogr_output, crs=PlateCarree(), color="coral", alpha=0.7)
for name in [
"split",
"multi-split",
"complex-split",
"two-holes",
"line",
"issues-124",
]:
plot(name)
ERROR 1: TopologyException: side location conflict at 234.90917500381769 14.76580303507545. This can occur if the input geometry is invalid. ERROR 1: TopologyException: side location conflict at 234.90917500381769 14.76580303507545. This can occur if the input geometry is invalid.