How to create a shapefile in Java using GeoTools?

How to create a shapefile in Java using GeoTools?

I’m trying to create & populate Shapefile in Java using GeoTools. Basically following this link (quite similar to the official documentation & other tutorials specifically for the point I’m asking below). For below code I’m getting first warning that FeatureCollections is deprecated and error that add () cannot be resolved.

Can a featuretype be retyped in GeoTools?

As featuretypes are immutable in GeoTools it is necessary to loop through the attributes and rename the geometry and then move it to first place while creating a new schema. DataUtilities.retype will reorder the attributes to match the new schema but as the geometry has changed name you have to copy the yourself.

How to convert shape files to CSV in Java?

I am trying to convert my shape files to csv through a batch processing in Java using Geotools. The problem is I have more than 500 shape files (point features). The code is working fine for a small number of shp files. But when I am iterating the process over a large dataset (number of files), some of the files are not written and of 0 KB.

Why are shapefiles so bad as a format?

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 – Long answer: Shapefiles suck as a format!

How to create shapefile in memory with GeoJSON?

If you are building your shapefile in memory why not just build a FeatureCollection and then dump that out as GeoJSON (or any other supported DataStore) Note: You will need to be working on master for the GeoJSON store as I haven’t backported it (no demand yet).

How to parse a GeoJSON file in Java?

And you want to load the geoJSON file in your program to test in this polygon contains the point, how could you do it in Java using JTS? Other option could be use GeoTools with GeoJson plugin but i’m not able to parse a GeoJson file

Why do I get an error reading GeoJSON file?

This error is due i’m trying to read a FeatureCollections from GeoJson file. It works if I tried with this simple string: