Hot answers tagged

14

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


12

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 solution depends on what you want to do with the parsed information.


8

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 available but at least most other alternatives are pure java. There is also one more alternative in OpenJUMP called "Sextante raster" which is also pure java. Different ...


8

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(CoordinateReferenceSystem crs, Point[] ...


7

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 image size, number of bands, or pixel values. Instead, it uses the GeoTools Coverage API. import org.geotools.coverage.grid.io.GridCoverage2DReader; import org....


7

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 imaging library called Apache Commons Imaging. It is a pure-Java library that consists of a single small JAR file. It also supports both reading and writing of ...


7

To parse or deserialize geojson in Java REST webservice, i prefere to use geojson-jackson , which integrate itself very nicely with jackson.


7

You need to import the GeoJSON plugn <dependency> <groupId>org.geotools</groupId> <artifactId>gt-geojson</artifactId> <version>${geotools.version}</version> </dependency> and then call it like this (a full example is here): public String geoData() { final GeometryBuilder builder = new ...


6

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 two lines: # Initial Java Heap Size (in MB) wrapper.java.initmemory=16 # Maximum Java Heap Size (in MB) wrapper.java.maxmemory=128 Seems to have done the ...


6

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


6

You can get it with JSTS. Check DistanceOp.js.


6

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 here). Hope this helps. import com.spatial4j.core.io.GeohashUtils; import java.awt.geom.Rectangle2D; import org.geotools.coverage.grid.GridCoverage2D; import ...


6

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 = 0; String ID = null; while(simpleFeatureIterator.hasNext()){ f = simpleFeatureIterator.next(); index = f.getID().lastIndexOf('.'); ...


6

Another alternative is GeoGson, which is built on top of Google's Gson: Geometry geometry = new GsonBuilder() .registerTypeAdapterFactory(new GeometryAdapterFactory()) .create() .fromJson("{\"type\":\"Point\",\"coordinates\": [23.5,20.125]}");


6

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 to a suitable projection for calculating areas in m^2.


6

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 https://sourceforge.net/p/jump-pilot/code/HEAD/tree/core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/analysis/GeometryFunction.java The idea seems ...


5

I was using Tomcat, and it's connection pooling facilities. I just exposed a datasource to my application through JNDI. Here's what did work for me: When I included the maven dependency for hibernate-spatial, it has a transitive dependency for hibernate itself, postgresql's jdbc and postgis's jdbc. So what I did was to remove these dependencies (outdated). ...


5

When I manually enter a Query for ways Overpass turbo suggests an auto repair so as to also get nodes for the way. This then amounts to way(poly:"50.7 7.1 50.7 7.2 50.75 7.15")["building"]; /*added by auto repair*/ (._;>;); /*end of auto repair*/ out body; see http://overpass-turbo.eu/s/1q1 . Change out body to out ids if you really only want way IDs, ...


5

With my (limited) experience in GIS, I can't recommend you to start such a big task while having very limited amount of time. This might provoke bad solutions and underestimates the amount of small problems with integrating different FLOSS solutions. After this warning I will try to answer: First thing is that you shall not store a whole planet dataset on ...


5

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 vector S(egment) = b - a vector N is normal to S (-ys, xs) vector P is coordinates of point You want to check the length of normal from point to Segment and ...


5

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; ... Dataset dataset = gdal.Open(filename); Band band = dataset.GetRasterBand(1); ... // Do some band operation, like band.ReadRaster() to get the data, whatever you ...


5

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


5

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

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"; File geojson = new File(url); File shpFile = new File("test.shp"); ShapefileDataStoreFactory dataStoreFactory = new ...


5

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) leaflet: how to After you can also try openlayers3


5

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> Then get an elevation with:- SELECT ST_Value(rast,1, ST_GEOMFROMEWKT('SRID=4326;POINT('||lon||' '||lat||')') ) This ...


5

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"); FeatureJSON featureJSON = new FeatureJSON(); FeatureCollection features = featureJSON.readFeatureCollection(states.openStream()); Then add them to a map with a style: ...


5

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 other kind of input. More likely, a mature framework will be preparing that query and running it using the :input as a parameter when executing prepared query, ...


5

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 as you have to handle each subpolygon in turn. The whole method becomes something like: static GeometryFactory gf = new GeometryFactory(); static public ...


5

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/rasterize.py With Java, you can use the same function from Java bindings https://github.com/OSGeo/gdal/blob/master/gdal/swig/java/javadoc.java#L733 (PS: ...


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