Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use mapshaper to simplify a region geometry #732

Merged
merged 4 commits into from
Jun 19, 2024

Conversation

ismaelbej
Copy link
Contributor

@ismaelbej ismaelbej commented May 31, 2024

  • Modify load-regions to use mapshaper to simplify a region using the distance parameter
  • Update load-friction-raster to pass the -cblend 1 option
  • Add -f parameter to load-regions to update an existing region
  • Set INTERVAL_DISTANCE=100 as default distance for simplification
  • Document new parameters in scripts/population/README.md

Closes #727

Copy link
Member

@ggiraldez ggiraldez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works but will not reprocess the existing regions (if I understand correctly) and we can't delete them and re-add them because they already have referencing projects.

It would also be nice to see the resulting size of the simplified shape, to adjust the interval if deemed necessary. For large countries (or large provinces) the default threshold may not be enough to reduce the size enough and still hog the CPU when performing spatial queries.

# interval= Specify simplification amount in units of distance.
# Uses meters when simplifying unprojected datasets in 3D space (see planar option below),
# otherwise uses the same units as the source data.
INTERVAL_DISTANCE=${INTERVAL_DISTANCE-1000}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please expand the comment above explaining that in our case since our GeoJSON are not projected (ie. use WGS84 coordinates) then this means the resolution for the simplified shape will be 1km? (Or at least that's what I understand from the documentation 😁)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure about what the parameter was measuring in this case. I compared the mapshaper output of the Kenya map or 100 and 1000 (it is the island on the south east)

Screenshot 2024-05-30 at 10 42 48 PM Screenshot 2024-05-30 at 10 46 03 PM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I'm thinking this can potentially lead to legitimate providers being excluded. Maybe we should play a bit with the thresholds and the problematic countries and check the resulting sizes. We may get away with a smaller threshold. @manumoreira what was the country that triggered the original issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, a default of 100 may work fine. I'm testing locally with some datasets I have and Philipines shrinks from 58 Mb to 2.5 Mb using 100 as the threshold. That should be acceptable I think, since Kenya's contour is 4.9 Mb unprocessed and we didn't have problems with that country so far. NB. sizes are of the admin level 0 .geojson files.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The country was Mozambique

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparison between the original and the 100 meters simplification

Screenshot 2024-05-31 at 10 14 44 AM

Copy link
Contributor Author

@ismaelbej ismaelbej May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to zoom more because the difference wasn't visible from https://mapshaper.org/. It is the same island from the previous screenshots on the south east of Kenya.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparison for Mozambique at the north betwee original resolution and 100m maps

Screenshot 2024-06-03 at 4 22 14 PM

Testing files
moz-geojson.tgz. I used https://mapshaper.org/ to load them in separate layers.

@ismaelbej
Copy link
Contributor Author

I'll add a -f to force updating the geometries.

ismaelbej added 2 commits May 31, 2024 10:10
* Add -f to force geometry updates
* Print sizes of files
Copy link
Member

@matiasgarciaisaia matiasgarciaisaia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't comment further on the task being done - I'll trust Gus' opinion on that.

scripts/population/load-regions Outdated Show resolved Hide resolved
scripts/population/load-regions Outdated Show resolved Hide resolved
Copy link
Member

@matiasgarciaisaia matiasgarciaisaia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

As a note for deployment, we'll probably need to manually fix the input file with the duplicate keys when running this in production.

@ismaelbej ismaelbej merged commit 6da765a into main Jun 19, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify region shapes in projects
4 participants