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);
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 ...
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()
...
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 ...
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 ...
6
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");
...
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 ...
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
...
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 ...
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 ...
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";
...
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)
...
5
votes
Accepted
How to combine LineStrings using JTS
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<...
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>...
5
votes
Accepted
Reproject features with geotools
This code works for me:
public static void main(String[] args) throws IOException, NoSuchAuthorityCodeException, FactoryException {
if(args.length==0) {
System.err.println("usage: ...
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 ...
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 ...
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/...
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://...
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/
...
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 ...
4
votes
Unit of Geotools' getArea function
As all of the questions you have linked to say JTS does not care about the units of your data and treats them all alike - so the answer to your question is square degrees. Now that is rarely (if ever) ...
4
votes
library to create static maps (an image) with custom map features
If your interested in using a microservice that you can run yourself, instead of a library check out https://github.com/trailbehind/StaticMapService/. You can install background layers into it, then ...
4
votes
Accepted
Exporting Shapefile to SVG using Java & GeoTools?
Have a look at the code referenced in my blog post which shows how to do exactly this, including styling the layer.
Here is the actual code:
private void exportSVG(File file) {
Dimension ...
4
votes
PostGIS: ST_Within returns "t"/"f" letters instead of "true"/"false" booleans
If you change the line
System.out.println(resultSet.getString(1));
to
System.out.println(resultSet.getBoolean(1));
you will get back a boolean value instead of a string.
4
votes
Accepted
Why modes are represented with numbers, that are powers of 2.?
So that we can combine them with the bitwise-or operator and then
separate them later. For instance, MODE_TRAINISH = MODE_TRAM |
MODE_RAIL | MODE_SUBWAY | MODE_FUNICULAR | MODE_GONDOLA;
If we ...
4
votes
Accepted
GeoWebCache Upgrade Error
A quick google of Unsupported major.minor version 51.0 leads to How to fix: Unsupported major.minor version 51.0 error?. Basically you need Java 7 for recent versions of GeoWebCache (and GeoServer and ...
4
votes
Accepted
is it possible to store empty geometries in an Oracle Database?
This is the question/response I got from oracle's spatial expert in Europe in 2014.
q:
Does oracle have the concept of an empty geometry? If so can you give me an example?
Would this be a valid way ...
4
votes
Accepted
How to calculate cell tower polygon and get the coordinates in wkt format
This is a fairly simple operation in Java using GeoTools. All you need to do is start at the tower and travel out a distance (radius) in the direction (azimuth) - probably minus some width parameter, ...
4
votes
Accepted
Modifying feature attributes of a shapefile in geotools
The only way to make these changes persistent is to write them out to disk (in any format you like). There is nothing to stop you using the same filename as you read in (if you feel brave) but making ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
java × 862geotools × 268
geoserver × 73
postgis × 66
gdal × 60
arcobjects × 58
shapefile × 57
jts-topology-suite × 43
coordinate-system × 42
openstreetmap × 40
geotiff-tiff × 39
geojson × 38
postgresql × 32
raster × 28
openlayers-2 × 22
software-recommendations × 21
android × 21
javascript × 20
geometry × 20
tomcat × 20
python × 18
wfs × 18
arcgis-desktop × 16
arcgis-server × 15
wms × 15