Ok, so I have done some more experimenting but I am having some minor problems.

First off, I seem to get smaller files when i simplify the features
separately as shown in the code from my previous post.  However,
occasionally the features overlap, especially along complex borders
like between VT and NH.

My new approach is as follows...

Geometry geoms[] = new Geometry[features.size()];
for (Iterator iter = features.iterator(); iter.hasNext();) {
        Feature f = (Feature) iter.next();
        geoms[f.getID()-1] = f.getGeometry();
}

GeometryCollection geom = new GeometryCollection(geoms, new GeometryFactory());
geom = (GeometryCollection)TopologyPreservingSimplifier.simplify(geom,0.01);

for (Iterator iter2 = features.iterator(); iter2.hasNext();) {
        Feature f = (Feature) iter2.next();
        f.setGeometry(geom.getGeometryN(f.getID()-1));
}

With the above approach, I do not get any overlapping features (at
least I didn't see any) but both solutions result in the same issue,
gaps between map features.  The algorithm doesn't always choose the
same points along joined edges of features so if I increase the
simplification I end up with gaps between states on the map of the
U.S.

I'm wondering if it is possible to simplify one shape at a time but
pass in a set of coordinates that cannot be removed.  That way once
the border along VT for example is established, the ajoining border in
NH will match exactly with no gaps.  Any thoughts on such an approach?
 I am not concert with any performance hit since this will be a batch
job performed offline from the actual application.

~ Chris

On Thu, Jul 23, 2009 at 4:00 PM, Chris Huyler<[email protected]> wrote:
> Thanks Martin and Stefan,  I am looking into
> TopologyPreservingSimplifier and it appears that does exactly what I
> need.
>
> I ran a quick test against a map of the US broken out by state and got
> the SHP file from 2,100K down to 200K and the level of detail is still
> sufficient for my application.  I'd like to get it smaller but if I
> set the simplification level higher than 0.01 the state borders don't
> line up with each other.  I think this is where your additional steps
> come in.  Here's my quick test code...
>
> File source = new File(sourceShpfile);
> ShapefileReader sr = new ShapefileReader();
> DriverProperties dpSource = new DriverProperties( source.getCanonicalPath());
> FeatureCollection features = sr.read(dpSource);
>
> for (Iterator iter = features.iterator(); iter.hasNext();) {
>        Feature f = (Feature) iter.next();
>        Geometry 
> tmp=TopologyPreservingSimplifier.simplify(f.getGeometry(),0.01);
>        f.setGeometry(tmp);
> }
>
> File dest = new File(destShpfile);
> DriverProperties dpDest = new DriverProperties( dest.getCanonicalPath());
> ShapefileWriter sw= new ShapefileWriter();
> sw.write(features, dpDest);
>
> I'll try to implement your suggestions, but any other tips would be welcome.
>
> Thanks again,
> ~ Chris
>
>> I assume that your dataset forms a polygonal coverage, right?  If so,
>> you can't just simplify each polygon individually - you need to process
>> them all together, to ensure that coverage topology is maintained.
>>
>> In this case, you need to do the following:
>> - dissolve the boundaries of the polygons to form unique line segments
>> - merge the line segments into linestrings which do not cross
>> - simplify the resulting linestrings (using
>> TopologyPreservingSimplifier, to avoid introducing intersections'
>> - polygonize the resulting line set
>> - use point-in-polygon tests to reattach the original polygon attributes
>> to the simplified polygons.
>>
>> You can do all this with the JUMP and JTS APIs - but there will be a bit
>> of code required to glue all the pieces together.
>
_______________________________________________
jump-users mailing list
[email protected]
http://lists.refractions.net/mailman/listinfo/jump-users

Reply via email to