Hot answers tagged

14 votes

converting/parsing geojson into com.vividsolutions.jts geometry

For a much more lightweight alternative to GeoTools, check out jts2geojson: GeoJSONReader reader = new GeoJSONReader(); Geometry geometry = reader.read(json);
user avatar
  • 12.4k
12 votes
Accepted

GeoJSON java library

Geotools as a support for geojson. See here. Otherwise, you could simply use a typical JSON parser (such as json-simple) together with the geoJSON spec, which is really easy to use. The best ...
user avatar
  • 9,947
8 votes

Looking for an open-source Java based GeoTIFF library

Install OpenJUMP and study what all has been gathered into it I have never really understood what all the alternatives are. ImageIO-ext is probably utilising native GDAL binaries if such are ...
user avatar
  • 52.3k
8 votes
Accepted

Calculate distance with JTS

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 ...
user avatar
  • 75k
7 votes

Reading each pixel of each band of multiband GeoTiff with GeoTools Java?

Mark's answer is great! It really helped me out. Here's a slightly modified version of Mark's code. The major difference is that this code does not rely on the java.awt.image package to compute the ...
user avatar
  • 315
7 votes
Accepted

Looking for an open-source Java based GeoTIFF library

I believe that I have found an adequate solution that meets all of my requirements. Thanks to user30184's answer, which pointed me in the direction of ImageIO, I was able to find an alternative Java ...
user avatar
  • 10.8k
7 votes

GeoJSON java library

To parse or deserialize geojson in Java REST webservice, i prefere to use geojson-jackson , which integrate itself very nicely with jackson.
user avatar
  • 4,490
7 votes

GeoJSON java library

Another alternative is GeoGson, which is built on top of Google's Gson: Geometry geometry = new GsonBuilder() .registerTypeAdapterFactory(new GeometryAdapterFactory()) .create() ...
user avatar
  • 177
7 votes
Accepted

How do I produce a GeoJSON with 1 point at a certain lon/lat?

You need to import the GeoJSON plugn <dependency> <groupId>org.geotools</groupId> <artifactId>gt-geojson</artifactId> <version>${geotools.version}</...
user avatar
  • 75k
6 votes

Avoiding GeoServer/Java out of heap space error?

I've had the same error message on a Windows Server with GeoServer using Jetty. After some research I found the file C:\Program Files (x86)\GeoServer 2.10.1\wrapper\wrapper.conf where I edited these ...
user avatar
  • 141
6 votes

How can I find closest point on a polygon from a point

You can get it with JSTS. Check DistanceOp.js.
user avatar
  • 9,947
6 votes
Accepted

Reading each pixel of each band of multiband GeoTiff with GeoTools Java?

I finally figured it out... this code assumes that the geotif is in wgs84 (4326) proj, but it works well for getting the lat long for each pixel, and the band values for each pixel (formatted as a csv ...
user avatar
6 votes

Converting shapefile to CSV file using GeoTools in Java?

I had same problem. I solved the problem. My solution: StringBuffer tmpStr = new StringBuffer(); tmpStr.append("ID,date,tstamp,X_prj,Y_prj,NEAR_FID,NEAR_DIST\n"); SimpleFeature f = null; int index ...
user avatar
6 votes
Accepted

Given a GeoJSON file how do I calculate the area of the embedded features?

GeoTools is a Java library which can read and write GeoJSON and provides access to features like area via the JTS library. It will also help you to reproject the geometries from the lat/lon of GeoJSON ...
user avatar
  • 75k
6 votes

Remove/Fill holes in Polygons from a MultiPolygon using JTS Topology Suite programmatically

OpenJUMP has a "remove holes" tool (and an advanced "remove small holes" tool as well). OpenJUMP often uses JTS rather directly but I am not sure about this case. The source code of the function is at ...
user avatar
  • 52.3k
5 votes

How can I find closest point on a polygon from a point

A very simple solution: solve an equasion for each pair of poly vertices. An algorithm for one segment of the polygon (gray in the picture) with points a and b: vector A is just point a coordinates ...
user avatar
  • 2,304
5 votes

How to Read&Write .tiff images in java using GDAL library

I guess you have gdal and the bindings installed, and some coding ability, so I'll just provide an outline: import org.gdal.gdal.gdal; import org.gdal.gdal.Band; import org.gdal.gdal.Dataset; ... ...
user avatar
  • 12.5k
5 votes

How to calculate the distance between a line and a point (using lat/lon coordinates)

you can't really convert convert distances in degrees into meters as the size of a degree varies as you approach the poles. convert your locations into a projected coordinate system, then calculate ...
user avatar
  • 1,362
5 votes

Testing if Geometry is convex using JTS?

OK, my original answer was wrong (see user30184's comment). Here's another: The polygon is convex if each interior angle is 180 degrees or less. You can check this in O(n) time, iterating over the ...
user avatar
  • 3,051
5 votes
Accepted

Create shapefile based on geojson data with geotools (Java)

Short answer: Your feature type doesn't match the Shapefile standard so the illegal bits get dropped by GeoTools. I have a utility class to fix this - try { String url = "geojson.json"; ...
user avatar
  • 75k
5 votes

Given a GeoJSON file how do I calculate the area of the embedded features?

You can do this several ways, I think that the easiest (if you only have a few GIS things to do) is to use Turf see here There are also a couple of GIS library whom are a bit heavier (size wise) ...
user avatar
5 votes

Looking for the simplest way to get elevation for a give wgs84 coordinate

You can download elevation data in raster format from this url Load each tif into postgres with:- raster2pgsql -d -s 4326 -t 50x50 <TIFF>.tif <YOUR TABLE> | psql -n <YOUR DATABASE>...
user avatar
5 votes
Accepted

Convert geojson to png

If you chose GeoTools it is a fairly simple process, fetch your geojson from somewhere: URL states = new URL("http://geojson.xyz/naturalearth-3.3.0/ne_110m_admin_1_states_provinces.geojson"); ...
user avatar
  • 75k
5 votes
Accepted

SQL injection with ST_geomFromGeoJson

It depends on what your library is actually doing with that query. If it's taking your GeoJSON input and slamming it all into a SQL string, then yes, it's an injection vector, but then so would any ...
user avatar
  • 19.4k
5 votes
Accepted

Remove/Fill holes in Polygons from a MultiPolygon using JTS Topology Suite programmatically

Basically, you need to create a new Polygon from the ExteriorRing of the input Polygon. gf.createPolygon(p.getExteriorRing().getCoordinateSequence()); There is a little more work with MultiPolygons ...
user avatar
  • 75k
5 votes
Accepted

How to convert GeoJSON to GeoTIFF

With the command line, https://gdal.org/programs/gdal_rasterize.html With Python, you can use gdal.RasterizeLayer like in the tests from GDAL e.g https://github.com/OSGeo/gdal/blob/master/autotest/alg/...
user avatar
  • 28.7k
5 votes
Accepted

PSQLException: ERROR: operator does not exist: public.geometry && public.geometry

Thanks @CL for Hint, search_path in java solved the problem, you can add comma separated multiple schema in currentSchema connection string parameter old connection url url: jdbc:postgresql://...
user avatar
  • 183
4 votes

converting/parsing geojson into com.vividsolutions.jts geometry

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/ ...
user avatar
  • 52.3k
4 votes

Point to Line Calculations

I would recommend to rely on GeographicLib implemented by Charles Karney which uses Gnomonic projection for point to line projections in WGS-84 (http://geographiclib.sourceforge.net/). This solution ...
user avatar
  • 425
4 votes
Accepted

Difference between ArcObjects SDK for Java and ArcGIS Runtime for Java?

With ArcGIS Runtime SDK for Java, you can write standalone applications, viewing / editing mostly ArcGIS Online data With the ArcObjects java SDK, you can do almost everything ArcMap can do. In fact, ...
user avatar
  • 1,274

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