21 votes
Accepted

Are mixed geometry types allowed in shapefiles?

Answer can be found from the official specification http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf. All the non-Null shapes in a shapefile are required to be of the same shape type. The ...
user avatar
  • 52.4k
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
10 votes

Are mixed geometry types allowed in shapefiles?

A shapefile does not support mixed geometry. A shapefile either consists of points, polylines or polygons, but not more than one. See this article for more: Shapefiles
user avatar
  • 2,062
9 votes
Accepted

Why do I get correct area and intersect area when use wrong projection?

"EPSG:3488, EPSG:NAD83(NSRS2007) / California Albers" is an equal-area projection. It is based on the Albers Conic, which is defined for the northern hemisphere. Because Sweden is within its range ...
user avatar
  • 67.6k
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

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
  • 75.1k
7 votes
Accepted

Difference between CoordinateSystem and CoordinateReferenceSystem

A Coordinate Reference System contains two different elements The datum: It defines how the CRS is related to the earth (position of the origin, the scale and the orientation of coordinate axis) e.g. ...
user avatar
7 votes
Accepted

Closing shapefile using org.geotools.data.shapefile.ShapefileFeatureReader gives warning?

You must close the iterators sfi and sfi2 after their respective loops. SimpleFeatureIterator sfi = fs.getFeatures().features(); double sum = 0; while (sfi.hasNext()) { SimpleFeature sf = sfi....
user avatar
  • 34.6k
6 votes

Why are date vaules displaying a trailing 'Z' when layers are published with Geoserver and a PostGIS data store?

It appears you were/are on the right track as the 'Z' is used for a timezone indicator, here is the source I found that best answers your question "Z" is kind of a unique case for DateTimes. The ...
user avatar
  • 11.9k
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

Difference between CoordinateSystem and CoordinateReferenceSystem

CoordinateReferenceSystem is the base Interface from which all other GeoTools SRS are derived from - it is the base class of Geocentric and Geographic projections (and others with vertical and ...
user avatar
  • 75.1k
6 votes
Accepted

Exporting WFS to shapefile?

The most likely reason to not see a geometry column in a Shapefile is that your column name is not the_geom. This is required by the ShapeFile standard - in an ideal world GeoTools would be smart ...
user avatar
  • 75.1k
6 votes
Accepted

Using Math in SLD file - wkt

You can do math in SLD in most places, but a WellKnownMark element is not one of them. This is what the standard says, GeoServer has a custom extension allowing to stick a CQL expression in the ...
user avatar
  • 15.7k
6 votes
Accepted

Understanding gdalwarp reprojection

Just display your raster in a GIS software in UTM 32N: You see that the raster is rotated in the new CRS, and the former Lower Left point is not the most southward point anymore. Since gdalwarp ...
user avatar
  • 75k
6 votes
Accepted

Which algorithm (Vincenty or Haversine) is used to calculate distance in GeoTools?

GeoTools uses Karney's GeographicLib, if you check the code you'll see it uses the Geodesic.Direct method.
user avatar
  • 75.1k
6 votes
Accepted

Unable to build a custom GeoServer WPS

The repository moved, and we were unable to get maven to handle a redirect. See the GeoTools Blog for more details. So now you need this in your pom.xml files: <repositories> <repository&...
user avatar
  • 75.1k
6 votes

How to create shapefile size greater than 2GB using GeoTools

As everyone said in the comments - you can't. Shapefiles use a 32bit pointer internally and it breaks if you go over 2Gb. Switch to a GeoPackage, fortunately as Datastores are interchangeable all you ...
user avatar
  • 75.1k
5 votes
Accepted

Coordinate conversion (EPSG:3857 to EPSG:4326) using OpenGIS/JTS too slow

You can use the GeodeticCalculator which should be faster. Something like: package com.envitia.spike; import org.geotools.geometry.DirectPosition2D; import org.geotools.referencing.CRS; import org....
user avatar
  • 75.1k
5 votes
Accepted

Defining coordinate reference system with rotation in GeoServer?

Ok, I've figured it out. It is possible to apply an affine transform onto some existing CRS using FITTED_CS. Below is an example of rotation of 60 degrees counterclockwise and movement: FITTED_CS["...
user avatar
  • 191
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
  • 75.1k
5 votes

Java library to break up a big polygon into many parts

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 ...
user avatar
  • 311
5 votes
Accepted

Geotools: unexpected difference between CRS.decode("EPSG:4326") and DefaultGeographicCRS.WGS84

I stumbled over a common pitfall. for EPSG:4326 the coordinate order should be latitude, longitude the javdoc for DefaultGeographicCRS.WGS84 state that the coordinate order should be longitude ...
user avatar
  • 161
5 votes
Accepted

Renaming column (attribute) name using GeoTools and shapefile:

You need to create a new FeatureType (schema) for your output DataStore with the new column names and then copy the features to the new type and write them out. Something like this will do it: ...
user avatar
  • 75.1k
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

SLD - break in hatch

The solution is to use something similar to something you already used in the past (for reference Using Math in SLD file - wkt), <PolygonSymbolizer> <Fill> <GraphicFill>...
user avatar
5 votes

Geometry from wkt/polygon using geotools

From the documentation use a WKTReader: GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); WKTReader reader = new WKTReader(geometryFactory); Point point = (Point) ...
user avatar
  • 75.1k
5 votes

GeoJSON to KML conversion

GeoTools will read GeoJSON and write KML quite easily: URL url = URLs.fileToUrl(new File("/home/ian/Data/states/states.geojson")); HashMap<String, Object> params = new HashMap<>(); params....
user avatar
  • 75.1k
5 votes

Specifying EPSG transformation method in GeoTools?

First you need to download the NTv2 file you need (e.g. from your national mapping agency), you then need to save the .gsb file in src/main/resources/org/geotools/referencing/factory/gridshift and ...
user avatar
  • 75.1k
5 votes
Accepted

Convert shapefile to PNG using GeoTools

To export any type of GeoTools feature type to an image the process is the same - you read in the features (or coverage) using a DataStore, you then render these features using a Style (often read ...
user avatar
  • 75.1k

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