...and apologies for all the typos in that reply - I hope you can
still decode it

On 24 March 2011 21:37, Michael Bedward <[email protected]> wrote:
> Hi John,
>
>> However, I don't know how to remove the coincident vertices. I am working
>> with a FeatureCollection from a shapefile, and the coincident vertices are
>> in polygons in separate features. Also, I think what I really need to do is
>> remove lines segments (2 or more consecutive vertices) that are covered by
>> line segments from a different feature.
>>
>> Is there a way to do that short of manually picking apart the geometries and
>> doing some sort of spatial search?
>
> If the vertices are coincident or nearly so, in terms of proximity to
> other vertices or they fall on line segments belonging to other
> polygons, then you should be able to remove then with
> TopologyPreservingSimplifier. I tried to show that with the example I
> posted.
>
>> I have a shape file composed of many features, each of which contains a
>> multi-polygon. In many cases, a line in a polygon from one shape file falls
>> completely within (inclusive) a line from another polygon (in a different
>> feature).
>
> As in colinear segments ? Or as in some boundary segments falling
> completely within another polygon ? Or both ? :)
>
>> I would like to remove those redundant lines, simplify the
>> resulting geometries (which would then no longer be closed polygons, but
>> line strings), and write the result out as a shape file or display it in a
>> DefaultMapContext.
>>
>> I don't know how to either detect those lines (other than just hand coding a
>> comparison algorithm and doing a huge brute force search), or prune them
>> out.
>
> Well, if your shapefile isn't massive the example code could be
> adapted to work with a feature collection like this...
>
>        PrecisionModel precModel = new PrecisionModel(precModelScale);
>        GeometryFactory gf = new GeometryFactory(precModel);
>
>        List<Geometry> geomList = new ArrayList<Geometry>();
>
>        SimpleFeatureIterator iter = inputFeatures.features();
>        try {
>            while (iter.hasNext()) {
>                SimpleFeature feature = iter.next();
>
>                // Note assuming here that we have a polygon shapefile
>                MultiPolygon mp = (MultiPolygon) feature.getDefaultGeometry();
>                final int n = mp.getNumGeometries();
>                for (int i = 0; i < n; i++) {
>                    geomList.add(mp.getGeometryN(i));
>                }
>            }
>
>        } finally {
>            iter.close();
>        }
>
>        GeometryCollection gcoll =
> gf.createGeometryCollection(geomList.toArray(new Geometry[0]));
>        Geometry merged = gcoll.buffer(0.0);
>
>        TopologyPreservingSimplifier tps = new
> TopologyPreservingSimplifier(merged);
>        tps.setDistanceTolerance(distanceTolerance);
>        Geometry simplified = tps.getResultGeometry();
>
> At this stage, the "simplified" object will probably be a single
> MultiPolygon (it's possible for it to be a single Polygon with holes
> for some input data).  Now the tricky bit is associating the
> components of your simplified Geometry with the original polygons so
> that you can create a new SimpleFeatureCollection, copying across all
> attributes from the original collection except for the geometries,
> which you want to replace with your new polygons.
>
> Um... I'm tempted to see I leave that as an exercise for the reader
> :-)  Instead I'll call out for help from other list members at this
> point...
>
> I *think* the best approach, for all but a tiny dataset, is to use a
> spatial index (Quadtree of STRtree in JTS). Insert each of the
> component polygons that make up the MultiPolygon object "simplified"
> into the index. The you can iterate through your original feature
> collection once more and use the bounds of each features geometry to
> query the index and find the best matching polygon.
>
> If I think of a less involved way I'll let you know. Meanwhile, we can
> also help others will chime in with better suggestions.
>
>> Another question: I notice that all of the classes you use are in
>> com.vividsolutions.jts packages. I am unclear as to when I should use those
>> (in general) and when to use those in org.opengis or org.geotools.
>>
>
> The simple rule of thumb when working with shapefiles (and many other
> data sources) is stick to JTS.
>
>> Also, with the example you gave, how would one take the resulting geometry
>> (result2) and the original geometries (poly1 and poly2) and put them into
>> features into a feature source so I can feed it to DefaultMapContext for
>> display? I have been taking things apart by looking at the methods on the
>> classes, but the javadocs don't give me guidance on how to build things, and
>> I haven't found a simple explanation of the precise meanings of the
>> components of composite objects such as features or schema, etc. I find
>> factory classes and factory finders, but there are pretty mysterious.
>>
>
> This is example app is a good place to start:
> http://docs.geotools.org/stable/userguide/examples/csv2shp.html
>
> Hope that helps,
>
> Michael
>

------------------------------------------------------------------------------
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