Bremersee GeoJSON for Spring Data MongoDB

This project contains converters for reading and writing GeoJSON from and into a MongoDB with Spring Data.

Лицензия

Лицензия

Категории

Категории

MongoDB Данные Базы данных Geo Прикладные библиотеки Geospatial JSON
Группа

Группа

org.bremersee
Идентификатор

Идентификатор

bremersee-geojson-spring-data-mongodb
Последняя версия

Последняя версия

2.0.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

Bremersee GeoJSON for Spring Data MongoDB
This project contains converters for reading and writing GeoJSON from and into a MongoDB with Spring Data.
Организация-разработчик

Организация-разработчик

bremersee.org

Скачать bremersee-geojson-spring-data-mongodb

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.bremersee/bremersee-geojson-spring-data-mongodb/ -->
<dependency>
    <groupId>org.bremersee</groupId>
    <artifactId>bremersee-geojson-spring-data-mongodb</artifactId>
    <version>2.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.bremersee/bremersee-geojson-spring-data-mongodb/
implementation 'org.bremersee:bremersee-geojson-spring-data-mongodb:2.0.0'
// https://jarcasting.com/artifacts/org.bremersee/bremersee-geojson-spring-data-mongodb/
implementation ("org.bremersee:bremersee-geojson-spring-data-mongodb:2.0.0")
'org.bremersee:bremersee-geojson-spring-data-mongodb:jar:2.0.0'
<dependency org="org.bremersee" name="bremersee-geojson-spring-data-mongodb" rev="2.0.0">
  <artifact name="bremersee-geojson-spring-data-mongodb" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.bremersee', module='bremersee-geojson-spring-data-mongodb', version='2.0.0')
)
libraryDependencies += "org.bremersee" % "bremersee-geojson-spring-data-mongodb" % "2.0.0"
[org.bremersee/bremersee-geojson-spring-data-mongodb "2.0.0"]

Зависимости

compile (4)

Идентификатор библиотеки Тип Версия
org.bremersee : bremersee-geojson jar 2.0.0
org.springframework.data : spring-data-mongodb Необязательный jar
org.mongodb : bson Необязательный jar
org.projectlombok : lombok Необязательный jar

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar

Модули Проекта

Данный проект не имеет модулей.

Bremersee GeoJSON

codecov

This project contains modules for reading and writing GeoJSON. The GeoJSON format is specified in rfc7946.

Maven Site

Usage

GeoJSON can be read or written with adding the GeoJsonObjectMapperModule to the ObjectMapper or without.

Without adding the GeoJsonObjectMapperModule to the ObjectMapper

If you do not add the GeoJsonObjectMapperModule to the ObjectMapper, you'll have to use the GeometryWrapper:

public class Example {
  
  public static void main(String[] args) {
    ObjectMapper om = new ObjectMapper();
    Point p = GeometryUtils.createPoint(10.2, 52.4);
    GeometryWrapper gw = new GeometryWrapper(p);
    String json = om.writeValueAsString(gw);
    System.out.println(json);
  }
}

GeoJsonFeature and GeoJsonFeatureCollection can be used without adding the module to the object mapper, too.

public class Example {
  
  public static void main(String[] args) {
    ObjectMapper om = new ObjectMapper();
    Point p = GeometryUtils.createPoint(10.2, 52.4);
    GeoJsonFeature f = new GeoJsonFeature("id", p, false, null);
    String json = om.writeValueAsString(f);
    System.out.println(json);
  }
}
With adding the GeoJsonObjectMapperModule to the ObjectMapper

If you add the GeoJsonObjectMapperModule to the ObjectMapper, you'll be able to process the geometry object directly:

public class Example {
  
  public static void main(String[] args) {
    ObjectMapper om = new ObjectMapper();
    om.registerModule(new GeoJsonObjectMapperModule());
    Point p = GeometryUtils.createPoint(10.2, 52.4);
    String json = om.writeValueAsString(p);
    System.out.println(json);
  }
}

Spring Data MongoDB Support

If you want to persist the JTS geometry objects to a MongoDB with Spring Data you'll have to register these converters:

@Configuration
public class PersistenceConfiguration {

  @Primary
  @Bean
  public MongoCustomConversions customConversions() {
    final List<Object> converters = new ArrayList<>(
        GeoJsonConverters.getConvertersToRegister(null));
    // add more custom converters
    return new MongoCustomConversions(converters);
  }
}

An entity may look like this:

@Document(collection = "feature")
@TypeAlias("Route")
public class RouteEntity {

  @Id
  private String id;

  @GeoSpatialIndexed(type = GeoSpatialIndexType.GEO_2DSPHERE)
  private MultiLineString geometry; // this is org.locationtech.jts.geom.MultiLineString

  private double[] bbox;

  private RouteProperties properties;

  // getter and setter
}

Версии библиотеки

Версия
2.0.0