Hot answers tagged

5

Look at Martin Davis (creator of the JTS Topology Suite), Lin.ear th.inking: Quirks of the "Contains" Spatial Predicate Geometry A contains Geometry B if no points of B lie in the exterior of A, and at least one point of the interior of B lies in the interior of A Geometry A covers Geometry B if no points of B lie in the exterior of A All that is ...


4

GeoTools provides a GeoJSON module which will read in GeoJSON files and convert them to GeoTools Feature Collections - the geometry elements of these collections is stored as a JTS object. So all you need is Geometry geom = (Geometry) feature.getDefaultGeometry();


4

The short answer is you can't do that unless your points are very close together and you want the answer in degrees. JTS knows nothing about units or the curvature of the earth. So you need to pull in some GeoTools jars that do know about such things. Then you can create a method like: private void calculateDistance( ...


3

I am not a Java developer and don't know of any existing Java implementations for this, but using the k-Nearest Neighbors algorithm with a k-d tree will likely give much better performance. However, if accuracy is important, you will need to implement the Haversine (spherical) or Vincenty (ellipsoidal) distance formulae for the distance metric, since ...


3

What you're trying to do doesn't really make sense. Quadtree.query works by intersecting the extents of the elements with a rectangular extent. It's up to you to further filter them. However, you can use the overloaded version of query with a subclass of ItemVisitor to achieve what you want. public class QtreeTest { public static class HoleVisitor ...


3

OK, my original answer was wrong (see user30184's comment). Here's another: The polygon is convex if each angle is 180 degrees or less. You can check this in O(n) time, iterating over the triples of points in the exterior ring and checking the sign of the determinant. import com.vividsolutions.jts.geom.Coordinate; import ...


2

There are a couple of different ways you can do this, and it will vary depending on the software you are using. But in QGIS you can use the Vector Grid tool, which is found in Vector - Research Tools. The tool allows you to set the extent of your working area based on a layer (in your case the polygon layer) and then output either a line or polygon grid ...


2

Try using Geometry.symDifference(Geometry) to merge them all together. Symmetric Difference is like an xor, see Wikipedia's explanation. I have tested merging a collection of jts Polygon that started off as holes and islands but were supplied as distinct Polygons and the result is as desired.


2

JTS saved the day! I wrote my own subroutine to do this by recursively subdividing a big geometry into pieces until each piece is less than a user-specified size. It goes like this: public static Collection<Geometry> split(Geometry g, int maxSize, int maxPieces) { if (maxSize < 1000) { throw new ...


2

JTS will just treat the lat/longs as Cartesian coordinates so as long as they don't cross the date line, the results will be as correct as the underlying implementation. If you're worried about the dateline, you can supply a translation to guarantee that never happens. However, depending on the projection you ultimately use and the shape of your geometries, ...


1

I would much rather suggest doing it manually since the math is simple. This will be much faster than using so many potentially complex methods. public static Point createPointInDistanceAtAngle(Point anchor, double distance, double angle) { double dx = distance * Math.cos(Math.toRadians(angle)); double dy = ...


1

Ok, so I found by myself the solution thanks to @user30184 comment. The key principal is using JTS rotation via Math Transformation. //my base point Coordinate ancorPoint = placeCoordinate; //create orthogonal point in distance of 0.001 arc degrees Coordinate endingCoordinate = new Coordinate(placeCoordinate.x+0.001, placeCoordinate.y); //rotate by 90 ...


1

JTS's DistanceOP#nearestPoints might be an easy way. I have not tested it. http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/operation/distance/DistanceOp.html#nearestPoints%28com.vividsolutions.jts.geom.Geometry,%20com.vividsolutions.jts.geom.Geometry%29 Compute the the nearest points of two geometries. The points are presented in the same ...


1

This is caused by the WKT and GML standards using a different convention for separating pair of points and each coordinate of a point. GML uses comma to separate coordinates and space to separate pairs, eg, 52.52735668,12.71762844 52.52633816,12.71518035 whereas WKT uses the opposite, eg, 52.52735668 12.71762844, 52.52633816 12.71518035 You have a ...


1

You could use the Java implementation of GeographicLib to solve the inverse geodesic problem on WGS84. import net.sf.geographiclib.*; ... private double calculateDistance( double lon1, double lat1, double lon2, double lat2) { GeodesicData g = Geodesic.WGS84.Inverse(lat1, lon1, lat2, lon2); return g.s12; // distance in ...


1

It looks like you are using an SVN checkout of JTS? You need to compile it then. Alternatively just use the precompiled binaries from http://sourceforge.net/projects/jts-topo-suite/files/jts/


1

Have a look at this documentation of CRS http://docs.geotools.org/latest/userguide/library/referencing/crs.html#well-known-text It is possible to set the CRS from WKT. The documentation says: CoordinateReferenceSystem can also be defined by a text format ((called “Well Known Text” or WKT). This is a standard provided by the OGC and shows up in ...


1

The algorithm for line densification isn't all that difficult (Pythagorean theorem for length and prorate dX and dY at the same ratio). The only tricky part is deciding between even distribution of spacing, or a fixed interval along the middle. You should evaluate the output of the existing method available within JTS before coding your own. The problem ...


1

Perhaps the OpenJUMP Jython tool "Rotated Rectangle Tool" can give some inspiration. Code is so short that I copy it all here: # Copyright (C) 2005 Integrated Systems Analysts, Inc. # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License import com.vividsolutions.jts.geom.Coordinate as ...


1

Probably the easiest way to think about this in terms of a union of the "is disjoint" and "touches only on the borders" cases. Those relationships are (imaginatively) known as "disjoint" and "touches". Here is an example in SpatiaLite: spatialite> SELECT ST_Touches(GeomFromText("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))"), GeomFromText("POLYGON((0 1, 0 2, 1 ...


1

There seems to be nowadays also native GeoJSON reader/writer code in JTS trunk: https://sourceforge.net/p/jts-topo-suite/code/HEAD/tree/trunk/jtsio/src/main/java/com/vividsolutions/jts/io/geojson/


1

For a much more lightweight alternative to GeoTools, check out jts2geojson: GeoJSONReader reader = new GeoJSONReader(); Geometry geometry = reader.read(json);



Only top voted, non community-wiki answers of a minimum length are eligible