If there is any method or class who can do the job. So, I want to know if I
don't miss something.
__-
-Original Message-
From: jts-devel-boun...@lists.jump-project.org
[mailto:jts-devel-boun...@lists.jump-project.org] On Behalf Of Martin Davis
Sent: donderdag 5 november 2009 17:54
To: JTS Topology Suite Development
Subject: Re: [jts-devel] Extend a LineString in a Polygon
Minze,
What do you mean by "still curious about the API support"?
Tolsma, Minze wrote:
> This Works fine for me. I'm still curious about the API support. :-)
>
> Thanks!
>
> Minze
>
> -Original Message-
> From: jts-devel-boun...@lists.jump-project.org
> [mailto:jts-devel-boun...@lists.jump-project.org] On Behalf Of Michael Bedward
> Sent: donderdag 5 november 2009 1:56
> To: JTS Topology Suite Development
> Subject: Re: [jts-devel] Extend a LineString in a Polygon
>
> Below is one way of doing it. I can almost guarantee there will be a
> much better way :)
>
> Michael
>
>
> import com.vividsolutions.jts.geom.Coordinate;
> import com.vividsolutions.jts.geom.Geometry;
> import com.vividsolutions.jts.geom.GeometryFactory;
> import com.vividsolutions.jts.geom.LineString;
> import com.vividsolutions.jts.geom.Point;
> import com.vividsolutions.jts.io.WKTReader;
>
> public class Foo {
>
> public static void main(String[] args) throws Exception {
> GeometryFactory gf = new GeometryFactory();
>
> WKTReader reader = new WKTReader(gf);
>
> Geometry poly = reader.read("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))");
> // a line inside the square
> LineString line = (LineString) reader.read("LINESTRING(4 4, 6 5)");
>
> if (!line.intersects(poly)) {
> System.out.println("line does not intersect polygon");
> return;
> }
>
> Coordinate[] coords = line.getCoordinates();
> final int END = coords.length - 1;
>
> // extend start point beyond poly
> Coordinate newStart = new Coordinate(coords[0]);
> Point testP = gf.createPoint(newStart);
> while (poly.contains(testP)) {
> newStart.x += newStart.x - coords[1].x;
> newStart.y += newStart.y - coords[1].y;
> testP = gf.createPoint(newStart);
> }
>
> // extend end point beyond poly
> Coordinate newEnd = new Coordinate(coords[END]);
> testP = gf.createPoint(newEnd);
> while (poly.contains(testP)) {
> newEnd.x += newEnd.x - coords[END-1].x;
> newEnd.y += newEnd.y - coords[END-1].y;
> testP = gf.createPoint(newEnd);
> }
>
> LineString extended = gf.createLineString(new
> Coordinate[]{newStart, newEnd});
> System.out.println("extended line: " + extended);
> System.out.println("crosses polygon: " + extended.crosses(poly));
> }
>
> }
> ___
> jts-devel mailing list
> jts-devel@lists.jump-project.org
> http://lists.refractions.net/mailman/listinfo/jts-devel
>
>
>
>
>
>
> This message contains information that may be privileged or confidential and
> is the property of the Capgemini Group. It is
> intended only for the person to whom it is addressed. If you are not the
> intended recipient, you are not authorized to
> read, print, retain, copy, disseminate, distribute, or use this message or
> any part thereof. If you receive this message
> in error, please notify the sender immediately and delete all copies of this
> message.
>
> ___
> jts-devel mailing list
> jts-devel@lists.jump-project.org
> http://lists.refractions.net/mailman/listinfo/jts-devel
>
>
--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022
___
jts-devel mailing list
jts-devel@lists.jump-project.org
http://lists.refractions.net/mailman/listinfo/jts-devel
This message contains information that may be privileged or confidential and is
the property of the Capgemini Group. It is
intended only for the person to whom it is addressed. If you are not the
intended recipient, you are not authorized to
read, print, retain, copy, disseminate, distribute, or use this message or any
part thereof. If you receive this message
in error, please notify the sender immediately and delete all copies of this
message.
___
jts-devel mailing list
jts-devel@lists.jump-project.org
http://lists.refractions.net/mailman/listinfo/jts-devel