From: Michael B. <mic...@gm...> - 2008-10-21 00:59:49
|
Hi Jo I think you want to do multiLineString.intersection( polygon ). This will give you a multi line string made up of lines within the polygon. If the lines cross within the polygon they will be cut at the crossing points. Here's a demo GeometryFactory gf = new GeometryFactory(); // polygon outer ring Coordinate[] outerCoords = { new Coordinate(0,0), new Coordinate(0,10), new Coordinate(10,10), new Coordinate(10,0), new Coordinate(0,0) }; LinearRing outerRing = gf.createLinearRing(outerCoords); LinearRing[] holes = null; Polygon poly = gf.createPolygon(outerRing, holes); Coordinate[] line1Coords = { new Coordinate(-100,2), new Coordinate(100,2) }; Coordinate[] line2Coords = { new Coordinate(-100,7), new Coordinate(100,7) }; Coordinate[] line3Coords = { new Coordinate(5, 100), new Coordinate(5, -100) }; LineString[] lines = { gf.createLineString(line1Coords), gf.createLineString(line2Coords), gf.createLineString(line3Coords) }; MultiLineString mls = gf.createMultiLineString(lines); MultiLineString within = (MultiLineString) mls.intersection(poly); for (int i = 0; i < within.getNumGeometries(); i++) { LineString line = (LineString) within.getGeometryN(i); System.out.println("line " + i + "(" + line.getStartPoint() + ") (" + line.getEndPoint() + ")"); } Hope this helps Michael 2008/10/15 Jo <new...@pu...>: > > Hello, > > I want to intersect a MultiLineString with a polygon. This operation should > return a cropped > MultiLineString. > polygon.intersection(MultiLineString) returns a Geometry which I can't cast > to the subclass > MultiLineString. > How can I convert the returned Geometry to a MultiLineString? Or is there > another way > how to make this intersection and get a cropped MultiLineString back. > > Thanks, > > Jo > > -- > View this message in context: http://n2.nabble.com/intersection-MultiLineString-Polygon-%3D-MultiLineString-tp1336428p1336428.html > Sent from the geotools-gt2-users mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Geotools-gt2-users mailing list > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > |