Hi John,

Here's an example illustrating one approach...


// Create two polygons with default (double) precision where the segments
// differ slightly in vertex location and number along their common
// boundary
WKTReader reader = new WKTReader();

Polygon poly1 = (Polygon) reader.read(
        "POLYGON((0 0, 0 10, 10 10, 12 8, 12 2, 10 0, 0 0))");

Polygon poly2 = (Polygon) reader.read(
        "POLYGON((24 0, 14 0, 12 2.01, 12 4.99, 12 7.98, 14 10, 24 10, 24 0))");

PrecisionModel pm = new PrecisionModel(0.1);  // no decimal places
GeometryFactory gf = new GeometryFactory(pm);
GeometryCollection gcoll = gf.createGeometryCollection(new Geometry[]
{poly1, poly2});
Geometry result = gcoll.buffer(0.0);

System.out.println(result);

// remove coincident vertices if you want
TopologyPreservingSimplifier tps = new TopologyPreservingSimplifier(result);
tps.setDistanceTolerance(0.1);
Geometry result2 = tps.getResultGeometry();

System.out.println(result2);

The output should be
POLYGON ((0 0, 0 10, 10 10, 12 8, 12 8, 14 10, 24 10, 24 0, 14 0, 12
2, 12 2, 10 0, 0 0))
POLYGON ((0 0, 0 10, 10 10, 12 8, 14 10, 24 10, 24 0, 14 0, 12 2, 10 0, 0 0))

Hope this helps,
Michael


On 23 March 2011 14:58, John Moore <[email protected]> wrote:
> I am a new user of Geotools and don't know how to solve a particular
> problem.
>
> I have a set of polygons representing the boundaries of United States
> Counties. Each county adjoins one or more other counties, so they share
> common boundaries. This means that there are cases where a line segment in
> county A's polygon is within a line segment of County B's polygon. There are
> other similar cases, all in which part of the line of one county is the same
> as part or all of the line of another county.
>
> I need to apply a simplifying algorithm to the county lines to reduce the
> number of points in them (for example, using TopologyPreservingSimplifier ).
>
> However, since these lines are not identical, if I simply apply the
> simplification to each county independently, the result is that the
> boundaries which were identical are no longer so.
>
> I have tried putting all of the polygons into one large MutliPolygon, and
> applying the algorithm, but it produces incorrect results (it simplifies one
> of the shared lines, but leaves the other instance of that line exactly as
> before).
>
> One approach would be to change the geometries so that the entire complex
> set of polygons has no common lines.
>
> How would I do that?
>
>
> Here is a picture of the problem, in characters:
>
> As shown on a map
>
> -----------------|
> | County A       |------------|
> |                Z County B   |
> |                |            |
> -----|           |-------------
>      |           | County C   |
>      |           |            |
>      ------------|            |
>                  |            |
>                  |____________|
>
> In this case, County A is a simple polygon with 6 line segments. County B
> has 4 and County C has 4.
>
> The western segment of County B is within the eastern segment of County A
> The western segment of County C overlaps the eastern segment of County A
>
> The "Z" in the A/B boundary represents a feature that simplification would
> change.
>
>
>  Thanks for any help
>
> John Moore
> Tiny Vital Systems LLc, Paradise Valley, AZ,
> USA
>
>
> ------------------------------------------------------------------------------
> Enable your software for Intel(R) Active Management Technology to meet the
> growing manageability and security demands of your customers. Businesses
> are taking advantage of Intel(R) vPro (TM) technology - will your software
> be a part of the solution? Download the Intel(R) Manageability Checker
> today! http://p.sf.net/sfu/intel-dev2devmar
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
>

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to