ivy
unread,Oct 24, 2011, 10:59:37 AM10/24/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to JSTS devs
Hi,
Can anyone explain to me how to use the PrecisionModels? Let's say
I've split a polygon p in two parts (pa, pb). I store and retrieve pa
in/from a database and projection transformations introduce very small
numerical errors. When I subtract p1 from the original polygon p
( p.difference(pa) ) I end up with multiple polygons, one with very
small area (due to the numerical error).
I tried to couple a GeometryFactory with a fixed PrecisionModel to the
WKTReader, but this doesn't work:
> var wkt1="POLYGON((10 10, 11 10, 11 11, 10 11, 10 10))"; // this is a square
> var wkt2="POLYGON((10 10, 11 10.0000000000001, 11 11, 10 10))"; // this is a triangle inside the square, with a 0.0000000000001 rounding error
>
> var precision = new jsts.geom.PrecisionModel(1000000);
> var rd = new jsts.io.WKTReader(new jsts.geom.GeometryFactory(precision));
>
> var p = rd.read(wkt1), pa = rd.read(wkt2);
> var dif = p.difference(pa);
>
> var wr = new jsts.io.WKTWriter();
> print(wr.write(p));
> print(wr.write(pa));
> print(wr.write(dif)); // this prints MULTIPOLYGON(((11 10.0000000000001,11 10,10 10,11 10.0000000000001)),((10 10,10 11,11 11,10 10)))
When I manually map the coordinates to my fixed grid, it does work:
> function PrecisionFilter(precisionModel) {
> this.filter = function(coord) {
> precisionModel.makePrecise(coord);
> }
> }
> PrecisionFilter.prototype = new jsts.geom.CoordinateFilter;
> var filter = new PrecisionFilter(precision);
>
> p.apply(filter);
> pa.apply(filter);
>
> dif = p.difference(pa);
> print(wr.write(dif)); // this prints POLYGON((10 10,10 11,11 11,10 10))
This still feels a bit ugly. What is the correct way of working with
precisionmodels? Can I couple them to the created polygons?
With kind regards,
Ivo