JTs algorithm package

Source: Internet
Author: User

Angle Analysis (Angle):

Com. vividsolutions. JTs. algorithm. Angle

Coordinate tip1 = new coordinate (); coordinate tail = new coordinate (); coordinate tip2 = new coordinate (); angle = new angle (); // returns the two undirected least difference angles in the range of [0,180] Double radia1 = angle. angle (tip1, tail); double radia2 = angle. angle (tail, tip2); system. out. println (angle. todegrees (angle. diff (radia1, radia2); // returns the smallest angle between two vectors. The range is [0,180] Double ang1 = angle. anglebetween (tip1, tail, tip2); system. out. println (angle. todegrees (ang1); // The direction from angle to angle. // public static final int clockwise =-1; clockwise // public static final int counterclockwise = 1; counter-clockwise system. out. println (angle. getturn (radia1, radia2); // determines whether the angle from tip1-> tail-> tip2 is an acute angle system. out. println (angle. isacute (tip1, tail, tip2); // determines whether the angle from tip1-> tail-> tip2 is an empty angle system. out. println (angle. isobtuse (tip1, tail, tip2); // angle-> radian conversion system. out. println (angle. todegrees (math. pi); // radians-> Angle conversion system. out. println (angle. toradians (180 ));

Output result:

11.309932474020213
168.6900675259798
-1
False
True
180.0
3.141592653589793

Basic Geometric algorithms (Cgalgorithms):

Com. vividsolutions. JTs. algorithm. cgalgorithms

Geometryfactory. Java

import com.vividsolutions.jts.geom.Geometry;import com.vividsolutions.jts.io.ParseException;import com.vividsolutions.jts.io.WKTReader;public class GeometryFactory {private WKTReader reader;private static GeometryFactory instance = null;public static synchronized GeometryFactory getInstance() {if (instance == null) {instance = new GeometryFactory();}return instance;}public void getReader() {reader = new WKTReader();}public Geometry buildGeo(String str) {try {if (reader == null) {reader = new WKTReader();}return reader.read(str);} catch (ParseException e) {throw new RuntimeException("buildGeometry Error", e);}}}

Private Static geometryfactory factory = geometryfactory. getinstance (); // defines the ring geometry G = factory. buildgeo ("linestring (0, 2, 5, 0 5, 0 0)"); coordinate [] coords = G. getcoordinates (); // points to the system on the ring. out. println (cgalgorithms. ispointinring (new coordinate (4, 4), coords); // point in the ring system. out. println (cgalgorithms. ispointinring (new coordinate (), coords); // calculates the shortest distance from line AB to CD. out. println (cgalgorithms. d Istancelineline (new coordinate (), new coordinate (); // calculate the shortest distance from A to CD. out. println (cgalgorithms. distancepointline (new coordinate (), new coordinate [] {new coordinate (), new coordinate )})); // whether the ring is clockwise oriented to system. out. println (cgalgorithms. isccw (new coordinate [] {new coordinate (1, 1), new coordinate (2, 0), n EW coordinate (), new coordinate ()}); // indicates whether the system is online. out. println (cgalgorithms. isonline (new coordinate (2, 1), new coordinate [] {new coordinate (2, 0), new coordinate (2, 2), new coordinate (1, 1 )})); // calculate the intersection of two lines and return coordinate points. Hcoordinate hcoord = new hcoordinate (new coordinate (), new coordinate (); try {system. out. println (hcoord. getx (); system. out. println (hcoord. gety ();} catch (notrepresentableexception E1) {// throw this exception, indicating that the two line segments are parallel. E1.printstacktrace ();} // equivalent hcoordinate Hd = new hcoordinate (); try {system. out. println (HD. intersection (new coordinate (), new coordinate ();} catch (notrepresentableexception E) {// throw this exception, indicating that the two line segments are parallel. E. printstacktrace ();} // relationship between the point and the object (geometry) // public final static int interior = 0; in the internal // public final static int boundary = 1; in the boundary // public final static int exterior = 2; in the external // public final static int none =-1; pointlocator PL = new pointlocator (); // online system. out. println (pl. locate (new coordinate (0, 0), factory. buildgeo ("linestring (0, 2, 5, 0 5)"); // on the system. out. println (pl. locate (new coordinate (0, 0), factory. buildgeo ("polygon (0, 5, 0,); // System in the plane. out. println (pl. locate (new coordinate (1, 3), factory. buildgeo ("polygon (0, 5, 0,); // system outside the surface. out. println (pl. locate (new coordinate (10, 10), factory. buildgeo ("polygon (0 0 ))")));

Output result:

True
True
1.4142135623730951
1.4142135623730951
True
True
2.0
2.0
(2.0, 2.0, Nan)
1
1
0
2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.