GithubHelp home page GithubHelp logo

Comments (7)

mbloch avatar mbloch commented on May 19, 2024

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.

jasadams avatar jasadams commented on May 19, 2024

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
screen shot 2014-04-16 at 9 39 22

Zooming into the bottom left hand corner you see where the problem is.
screen shot 2014-04-16 at 9 25 14

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

screen shot 2014-04-16 at 9 40 39

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.

mbloch avatar mbloch commented on May 19, 2024

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.

mbloch avatar mbloch commented on May 19, 2024

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.

MarcusMapMaker avatar MarcusMapMaker commented on May 19, 2024

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.

jasadams avatar jasadams commented on May 19, 2024

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.

mbloch avatar mbloch commented on May 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.