# Tag Info

## Hot answers tagged jts-topology-suite

14

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

12

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

8

In the conversion world, what you've built is known as a "bowtie". If you really want that shape, you need to conform to topology rules by making a multipart polygon with "left hand rule" part vertices {0,0},{0.5,0.5},{0,1},{0,0} and {0.5,0.5},{1,0},{1,1},{0.5,0.5} (reverse the order [or just swap vertices 2 & 3 in each part] to generate "right hand ...

7

You need to understand the definition of the spatial predicates. What you're really want is to know if a line traverses the polygon (and not simply cross it) Using the JTS Topology Suite, you can see that in both cases the predicates are the same: the two lines intersects and crosses the polygon: and With the JTS Topology Suite, you can use the ...

7

JTS Testbuilder is a java program: It works on linux as well. You only need to launch the testbuilder.sh file in the jts-1.xx/bin folder.

7

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

7

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

5

The official website of the JTS Topology Suite API is http://tsusiatsoftware.net/jts/main.html This points to the SourceForge page as the official download site and source repository.

5

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();

5

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

5

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

5

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

5

They are the same project JTS moved to Location Tech on Nov 3, 2016. AFAIK (and looking at the github repo) there has not yet been a released version from the LocationTech branch. So you should probably continue to use the Vivid Solution's release until a new version comes out, unless you have to be on the bleeding edge. UPDATE 12/2018 There is now a JTS ...

5

To expand on the answer given by tinlyx, you will not miss anything as PostGIS utilizes the GEOS library, which is a direct C++ port of JTS, for many of its spatial functions. In addition, PostGIS uses gdal under the hood and proj4, for transforming from one coordinate system to another. PostGIS also supports a raster datatype, so you can do raster/vector ...

4

From @Mike Toews' tip: @Entity @Table(name="cities") public class City { @Type(type = "org.hibernate.spatial.GeometryType") @Column(name="the_geom") private Point theGeom; public String asJson() { GeometryJSON g = new GeometryJSON(); return g.toString(theGeom) ; } } You will need at least these JARs: gt-api-10.0.jar ...

4

Always be aware of the axis order. PostGIS always uses the axis order: longitude (x), latitude (y). -- Somewhere in Chicago, USA SELECT ST_AsText(ST_Transform(ST_SetSRID(ST_Point(-87.642970, 41.937832), 4326), 3857)); -- POINT(-9756370.79201015 5151671.52336743) -- Somewhere in Antarctica SELECT ST_AsText(ST_Transform(ST_SetSRID(ST_Point(41.937832, -87....

4

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/ EDIT OpenJUMP can read and write GeoJSON with code that is in https://sourceforge.net/p/jump-pilot/code/HEAD/tree/core/trunk/src/com/vividsolutions/jump/io/...

4

Assuming that your polygons never overlap then you can generate a multipolygon from them using something like: Polygon[] polygons = new Polygon[]{poly1,poly2}; GeometryFactory factory = new GeometryFactory(....); MultiPolygon combined = new MultiPolygon(polygons, factory); If they might overlap then you will need to test them for intersects and ...

4

I would not use a conventional point->polygon process because that expects your points to define the boundary of a polygon and it doesn't sound like yours do. It sounds like yours are hotspots that are somehow related. However, there are lots of ways to create polygons for this sort of situation depending on what is sensitive in your data. Here's a few ...

4

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

4

In NTS, every object that inherits ILinarRing interface has the IsCCW property to test if it is counter clockwise. In case of a MultiPolygon object, you have to test the shell of every internal polygon. Like this: IMultiPolygon multiPol = rdr.Read<MultiPolygon>(geoJson); foreach (IGeometry geom in multiPol.Geometries) { IPolygon pol = (IPolygon)...

4

I don't think you need JTS per se. PostGIS uses GEOS, a C++ port of the Java library JTS.

4

You need to create a GeometryCollection of the polygons that you wish to join and then call .union() on it. So you'll need some code like: String lines = "/tmp/ian.shp"; GeometryFactory factory = new GeometryFactory(); Map<String, Object> params = new HashMap<>(); params.put("url", URLs.fileToUrl(new File(lines))); DataStore ds = ...

4

My first approach was giving me wrong results (wrong circle - a vertically elongated ellipse). It is not the right one because (to quote @whuber): "Because Mercator projections are conformal, a small circle (and 10 km radius is very small compared to the globe) should appear on the map as a circle, period". After @user30184 help/comment/suggestion, ...

4

I think all of the JTS methods relating to distance are looking for the nearest or shortest. But providing you don't have too many vertices then you could do a brute force O(N*N) search: GeometryFactory gf = new GeometryFactory(); double maxDist = 0; Point start = null, end = null; for (Coordinate c : geom.getCoordinates()) { Point p = gf.createPoint(c); ...

3

There's also a solution using Gonomonic projection presented by Charles Karnes in Algorithms for geodesics. There is an implementation in Java available with Barefoot library: https://github.com/bmwcarit/barefoot SpatialOperator spatial = new Geography(); Point reykjavik = new Point(-21.933333, 64.15); Point moskva = new Point(37.616667, 55.75); Point ...

3

Finally I found a java utility that do the job right away http://biodiversityinformatics.amnh.org/open_source/pdc/documentation.php

3

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

3

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

3

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

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