Skip to content

Ideas for additional checks for "scratches" or shapfile lines crossing the image #102

@djhoese

Description

@djhoese

Problem description

There are various cases where due to the nature of shapefiles in lon/lat space and images in various projections' space, that you get drawn lines from shapefiles that go straight across the image. This essentially comes from "point N" of a polygon mapping to the outside left side of the image and "point N +1" mapping to the outside right side of the image and pycoast drawing a line connecting these two points. This often happens because the points straddle the anti-meridian of the target projection or the anti-meridian of the lon/lat space (-180/180) depending on the shapefiles used.

@lobsiger had done some work in the past to minimize the number of these lines in #59 and I think a couple other PRs. I'm starting this issue to talk about other options that weren't implemented yet and I think could easily be added, but may affect performance.

The Code

The main part of the code that would be modified is this method here:

if (x >= 1e30).any() or (y >= 1e30).any():

This line is essentially a boolean mask used to say "is this point valid in this projection" and is used in a later line to determine where to split a polygon into smaller segments to avoid drawing a line from point N to point N+1 where it would draw a large non-real line across the image.

Adding any additional conditions to this should be easy as we can just do a boolean AND or OR with a numpy array.

Possible solutions

My first thought was to take the difference between each coordinate point in the X dimension (the only dimension that has wrapping/non-contiguous coordinates) using np.diff and look for anything larger than the X-extents of the image. I realized later that this could be a problem for very small geographic regions where the points for larger features like country borders and coastlines might be much further apart than looking at a single province or city, even though you'd still want the line to show up.

My next thought was still to do the np.diff but to maybe look for any difference larger than X degrees/meters (depending on the output projection). A good value for this could be determined offline (not at runtime, just store it in a constant) by taking all the GSHHG shapefiles/polygons and determine the largest difference between their points in geocentric meters. This should give a clear indication of "point N is at location A, but point N+1 is at location A+10000000 meters" and work for global images and local (city-level) images. @lobsiger's existing checks should limit polygons that are completely outside the image already, but this will handle the anti-meridian case...I hope.

Thoughts @mraspaud @lobsiger ?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions