Comments (7)
This seems like a reasonable request. Before making the change I'd like to investigate the kinds of problems you're seeing when applying precision to datasets with lots of small features. I'm guessing that the same kinds of errors will also occur if rounding is applied on export (just fewer of them). It would be nice if mapshaper could repair the errors automatically.
The original reason for rounding coordinates on import was to provide a crude way of snapping together slightly misaligned polygon boundaries, so that mapshaper's topology function could identify shared boundaries correctly.
The --auto-snap and --snap-interval options were added after --precision. They provide a better way of snapping together misaligned coordinates.
from mapshaper.
Here is what I was trying to do and what happened.
I am trying to reduce a shape file for viewing when zoomed right out. As it will be loaded in the browser I wanted the file to be as small as possible. When viewing the entire country of Australia, I did not think we needed 6 decimal places of resolution so I used the precision option to reduce this.
mapshaper -p 0.005 --precision 0.0001 -f geojson -o SA2_2011_AUST.json SA2_2011_AUST.shp
The "SA2_2011_AUST.shp" file is available from the ABS
No errors are reported, however when trying to create a 2dsphere index on the features in mongo, I get a "malformed geometry" for some of the features. On inspecting the features with these errors, I get invalid polygons as shown in the image below
Zooming into the bottom left hand corner you see where the problem is.
Running the above command but with 6 decimal places of precision results in no errors when loading into mongo and the following polygon for the same feature:
mapshaper -p 0.005 --precision 0.000001 -f geojson -o SA2_2011_AUST.json SA2_2011_AUST.shp
It would only be a small reduction in the file size if I was able to reduce the precision further so its not a big deal for me, the biggest cost for me was in the time trying to figure out what was going on. I'll leave it up to you to determine whether the effort involved in addressing this problem is worth it. Let me know if you need anything else from me
from mapshaper.
This is very helpful, thanks.
Ideally, mapshaper should be able to round coordinates while avoiding the kind of geometrical errors that you ran into. Some of the cases that would need to be handled are:
- Small shapes collapsing to a single point
- Spikes (what you encountered)
- Self intersections
It would be pretty easy to remove spikes, but handling self intersections is trickier.
A general solution for repairing corrupted polygons would be to increase the precision of coordinates in problem areas until the geometry is clean again.
(The same solution could be applied to geometrical errors in quantized TopoJSON output. This would require updating the relevant part of the TopoJSON spec to allow floating point coordinates in quantized datasets @mbostock)
from mapshaper.
In the "better late than never" department, v0.2.4 has an option for setting coordinate precision on export. In addition to rounding coordinates, Mapshaper also tries to remove spikes and other geometry problems that might be introduced by rounding.
Mapshaper's syntax has changed a bit since this issue was first added. This is how the command would by written now:
mapshaper SA2_2011_AUST.shp -simplify 0.005 -o format=geojson precision=0.0001 SA2_2011_AUST.json
from mapshaper.
Hi Matthew,
Very useful research and a great implementation you've created with mapshaper. As the spatial data manager at the Australian Bureau of Stats I was just wondering why you selected Australian data to use in your example? No real reason just curious :-)
Dynamic generalisation is one of those ideas that I've yet to see implemented in online maps, but which will have a big impact when someone does it well.
cheers,
Marcus Blake
Assistant Director
Geography Section
Australian Bureau of Statistics
[email protected]
Sent from my iPad
On 28 Aug 2014, at 5:33, Matthew Bloch [email protected] wrote:
In the "better late than never" department, v0.2.4 has an option for setting coordinate precision on export. In addition to rounding coordinates, Mapshaper also tries to remove spikes and other geometry problems that might be introduced by rounding.
Mapshaper's syntax has changed a bit since this issue was first added. This is how the command would by written now:
mapshaper SA2_2011_AUST.shp -simplify 0.005 -o format=geojson precision=0.0001 SA2_2011_AUST.json
—
Reply to this email directly or view it on GitHub.
from mapshaper.
Hi Marcus,
I requested this feature as I am using mapshaper for a project I am working on and thought this feature would be useful to reduce the size of the geojson files. I will be trying it out in the coming weeks.
The project (https://territory.guru/) is Australian based and that is why I used an ABS shape file. I don't do dynamic generalisation but I do use mapshaper to create different resolutions based on zoom level.
Regards,
Jason
from mapshaper.
v0.2.4 added an option to set precision on output (-o precision=
). v0.2.7 fixed a couple of related bugs. Closing the issue.
from mapshaper.
Related Issues (20)
- 1 degree x 1 degree graticule and source units HOT 1
- Warn when exporting SVG paths with more than 32,000 vertices
- light blue paths and performance HOT 3
- Memory usage almost 4x size of input geojson file HOT 4
- Filter lines still create polygons HOT 5
- When hovering mouse over feature and scrolling, fill color freaks out HOT 1
- Point layers and data layers do not show up HOT 2
- Cannot convert between WGS84 and Webmercator after converting and saving data as EPSG:3857. HOT 3
- Error on simplifying GeoJSON file HOT 11
- Javascript error related to polygon editing causes GUI to crash HOT 1
- There is an issue when you import a shapefile HOT 2
- Clip command removes Features visually but not from exported file. HOT 4
- Sticky hand HOT 1
- snap effects multiples layers HOT 1
- geojson from points HOT 2
- Export failed Export failed for an unknown reason HOT 3
- topojson files in power bi HOT 2
- Problem in drawing polygon and importing snapshot file HOT 4
- Export to Shape File Not working HOT 12
- Bug: can't open snapshot file I created on mapshaper.org HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mapshaper.