# Tag Info

6

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

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

4

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 com.vividsolutions.jts.geom....

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

For this scenario, I would suggest using the JTS GeometryPrecisionReducer class rather than GeometrySnapper. GeometrySnapper is intended for snapping one geometry to another. If you wanted to use GeometrySnapper, you could generate a fishnet grid at your desired precision level to snap to. But GeometryPrecisionReducer provides the same result without ...

3

You need to close the polygon by adding the start point to the end of the list of points that you build the WKT with. So change it to: for (var z = 0; z < arreglo.length; z++) { arreglo2.push(arreglo[z][0]+" "+arreglo[z][1]); } arreglo2.push(arreglo[0][0]+" "+arreglo[0][1]); But I'm pretty sure you can use the OpenLayers WKT ...

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

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

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

From your drawings and the comments I think your requirements are that the line intersects with the interior of the polygon does not just touch the boundary of the polygon Just combine the requirements. This is the method using JTS that should answer your question: public static boolean lineReallyIntersectsPolygon(LineString ls, Polygon p){ if(ls....

2

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

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

2

The KML Encoder (like most of GeoTools) works with features not geometries so you need to wrap your polygon in a feature, this gives you the opportunity to add some attributes to make your KML more useful too. public static void main(String[] args) throws IOException { File t = new File("test1.kml"); SimpleFeatureTypeBuilder builder = new ...

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

1

I think your problem is that none of your strings overlap so there is nothing for the union to do. I've tried the following code: SimpleFeatureIterator itr = features.features(); ArrayList<Geometry> geometries = new ArrayList<>(); try { while(itr.hasNext()) { SimpleFeature f = itr.next(); Geometry geom = (Geometry)f....

1

The easiest way is to use GeoTools to create a DataStore based on your database (since you don't say which one you are using I can't show an example). Then you can list the geometry for each of the features (the rows of the tables) and do whatever you intend to do with them.

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

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

I am not sure if this is a more efficient way but you could also compare the area of the input polygon to the area of the convex hull of the same polygon. Idea: The area of the convex hull of a concave polygon is always bigger then the area of the concave polygon itself. Simple method: public static boolean isConvexPolygon(Polygon p){ // calculate ...

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

This is a very hard and long winded way of doing it, you really should use GeoTools' datastores (which abstract all this work away) So assuming that what you actually want is to write some geometries and attributes to PostGIS you can do this: Decide what is in your dataset and convert your objects to Features (usually SimpleFeatures): SimpleFeatureType ...

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 documentation is sparse indeed, http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/util/GeometricShapeFactory.html#createArc%28double,%20double%29 just says: public LineString createArc(double startAng, double endAng) Creates a elliptical arc, as a LineString. "Ang" suggests "angle". The best way to find out is playing with it. I ...

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 2,...

1