Search code examples
javageotools

In geotools ,how to use Geometry as feature source add into layer?


In geotools ,how to use geometry as feature source add into layers?

I know that .shp file can add into layers, and add into content,then we can show it. I read it in geotools quickstart: http://docs.geotools.org/latest/userguide/tutorial/quickstart/intellij.html

but I want to show the geometry object in content, I need to use geometry object as feature source replace shap file.(It's right?) So how to do it? I only konw that how to get geometry's WKT and geojson.

thank you!


Solution

  • GeoTools will only display Features so you need to create a Feature and add your Geometry object to the feature. You will also need to know the projection of your geometry if you plan to display it with other data sets (e.g. shapefiles).

    If you look at the Feature Tutorial you will see a worked example of how to create a FeatureType and how to make Features using it. The QuickStart tutorial shows how to display features on the screen.

    The utility class DataUtilities provides methods for converting lists of features to FeatureCollections and FeatureSources.

    You mention WKT and GeoJSON as possible sources so you will want to explore the JTS.WKTReader and the gt-geojson module for help parsing those formats into Geometries that GeoTools can make use of.