21

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 values for shape type are as follows: Value Shape Type 0 Null Shape 1 ...


14

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


10

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


9

"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 of definition, it is equal-area in Sweden. This means that (up to floating point rounding error) it will give absolutely correct areas. Neither the Mollweide ...


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

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


7

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. ED50, ETRS89. The datum can be a geodetic datum, a vertical datum or a engineering / local datum. The coordinate system: describes how the coordinates ...


7

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.next(); MultiPolygon mp2 = (MultiPolygon) sf.getDefaultGeometry(); Polygon p2 = (Polygon) mp2.getGeometryN(0); SimpleFeatureIterator sfi2 = fs2....


6

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 literal "Z" is actually part of the ISO 8601 datetime standard for UTC times. When "Z" (Zulu) is tacked on the end of a time, it indicates that that time is UTC, ...


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

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

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 temporal coordinates). It comes from the ISO19111 specification by way of the OGC GeoAPI project. CoordinateSystem is also an interface that comes from ISO19111 and ...


6

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 enough to fix this for you behind the scenes, but no one has contributed that code yet! So you will need to inspect the schema of your features from the WFS and ...


6

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 middle of a mark name like this: wkt://LINESTRING(0 0, ${Orientation * 200} 33) I could not try it out, but it should work.


6

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 always produces a rectangle parallel to the axes of the new projection, the new corner points are different from the UTM31N corner points.


6

GeoTools uses Karney's GeographicLib, if you check the code you'll see it uses the Geodesic.Direct method.


6

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> <id>osgeo</id> <name>OSGeo Release Repository</name> <url>https://repo.osgeo.org/repository/release/</url> ...


6

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 will need to do is change the parameters you are creating it with. HashMap<String, Object> map = new HashMap<>(); map.put(GeoPkgDataStoreFactory....


5

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.geotools.referencing.GeodeticCalculator; import org.opengis.referencing.FactoryException; import org.opengis.referencing.NoSuchAuthorityCodeException; import org....


5

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["BPAF", PARAM_MT["Affine", PARAMETER["num_row", 3], PARAMETER["num_col", 3], PARAMETER["elt_0_0", -0.5], PARAMETER["elt_0_1", -0....


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

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

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 latitude So you should choose wisely which CRS you use when e.g. parsing external WKT strings as I did. More in-depth explanations of why this is the case are found ...


5

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: DataStore inputDataStore = DataStoreFinder.getDataStore(Collections.singletonMap("url", inFile.toURI().toURL())); String inputTypeName = inputDataStore....


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

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> <Graphic> <Mark> <WellKnownName>wkt://LINESTRING(${cos(Nagib)*-20} ${sin(Nagib)*-20}, ${cos(...


5

From the documentation use a WKTReader: GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); WKTReader reader = new WKTReader(geometryFactory); Point point = (Point) reader.read("POINT (1 1)");


5

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.put(GeoJSONDataStoreFactory.URLP.key, url); DataStore in = DataStoreFinder.getDataStore(params); if(in == null) { throw new IOException("couldn't open ...


5

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 proceed as normal. If you need a custom transform there are some examples in the GeoServer documentation. For example this program: import org.geotools....


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