# jts2geojson
**Repository Path**: z954134/jts2geojson
## Basic Information
- **Project Name**: jts2geojson
- **Description**: JTS from/to GeoJSON converter for Java
- **Primary Language**: Java
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2024-06-07
- **Last Updated**: 2024-06-07
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
## Introduction
This Java library can convert JTS geometries to GeoJSON and back. Its API is similar to other io.* classes in JTS.
[](https://github.com/bjornharrtell/jts2geojson/actions/workflows/maven.yml)
## Maven
```xml
org.wololo
jts2geojson
0.18.1
```
## Usage
```java
GeoJSONWriter writer = new GeoJSONWriter();
GeoJSON json = writer.write(geometry);
String jsonstring = json.toString();
GeoJSONReader reader = new GeoJSONReader();
Geometry geometry = reader.read(json);
```
## Features and FeatureCollections
JTS does not have anything like GeoJSON Feature or FeatureCollection but they can be parsed by this library. Example:
```java
// parse Feature or FeatureCollection
Feature feature = (Feature) GeoJSONFactory.create(json);
FeatureCollection featureCollection = (FeatureCollection) GeoJSONFactory.create(json);
// parse Geometry from Feature
GeoJSONReader reader = new GeoJSONReader();
Geometry geometry = reader.read(feature.getGeometry());
geometry = reader.read(featureCollection.getFeatures()[0].getGeometry());
// create and serialize a FeatureCollection
List features = new ArrayList();
Map properties = new HashMap();
features.add(new Feature(geometry, properties));
GeoJSONWriter writer = new GeoJSONWriter();
GeoJSON json = writer.write(features);
```