Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript
https://turfjs.org/
MIT License
9.33k stars 943 forks source link

simplify #17

Closed morganherlocker closed 10 years ago

morganherlocker commented 11 years ago

Takes a collection of detailed polygons and smooths out the edges to a given tolerance. It will probably use a Ramer Douglas Peucker algorithm or something similar. This will probably require the use of topojson to maintain edge integrity of geographies.

g.simplify(polys, 2000, function(err, smoothed){
  console.log(smoothed)
})
morganherlocker commented 11 years ago

This is being changed to "simplify", since that is what douglas peucker really does. mapshaper will be used for this.

morganherlocker commented 10 years ago

stubbed out, but need to figure out how to properly use topojson from node.

calvinmetcalf commented 10 years ago

You need to figure out quantization and simplification, if you have them as q and s with geojson geojson

function(q,s,geojson){
    var options = {
        "quantization" : q,
        "minimum-area" : s,
        "property-transform": function (properties, key, value) {
             //keeps all
             properties[key] = value;
             return true;
         }
    }
    var topo =topojson.topology({name:geojson}, options);
    topojson.simplify(topo,options);
    return topojson.feature(topo, topo.objects.name);
}
morganherlocker commented 10 years ago

Perfect, that is great. I will implement this in the next couple days.

Thanks!

morganherlocker commented 10 years ago

This feature has been implemented. I will add an example to the docs shortly.

LarsBuur commented 10 years ago

Hi Morgan,

It great to be able to do this on Polygons. I would very much like the ability to apply simplification on LineString. While at it - it would also be nice to be able to apply simplification on a single polygon or LineString.

Cheers, Lars

calvinmetcalf commented 10 years ago

might look into simplify-js for stuff where topojson is overkill

morganherlocker commented 10 years ago

Hey Lars,

It will currently work on a feature collection of polygons. I think it will work on a feature collection of linestrings too. I will write a test for the lines. As far as the single features go, I think that is a great idea and will be simple to add in. I will reopen this issue until I have both of these things resolved.

calvinmetcalf commented 10 years ago

topojson (and the snippit I wrote) should work fine for any sort of feature collection of any of the 7 types in any combination (obviously points don't get simplified)

On Thu, Dec 5, 2013 at 8:44 AM, Morgan Herlocker notifications@github.comwrote:

Hey Lars,

It will currently work on a feature collection of polygons. I think it will work on a feature collection of linestrings too. I will write a test for the lines. As far as the single features go, I think that is a great idea and will be simple to add in. I will reopen this issue until I have both of these things resolved.

— Reply to this email directly or view it on GitHubhttps://github.com/morganherlocker/turf/issues/17#issuecomment-29898149 .

-Calvin W. Metcalf

morganherlocker commented 10 years ago

@calvinmetcalf @LarsBuur I added tests for for the various feature types and everything is passing https://github.com/morganherlocker/turf/blob/master/test/simplify.js

LarsBuur commented 10 years ago

Great! - thank you very much. I will look into the simplification and report back.