Custom MongoDB codec for JTS (GeoTools)?

346 Views Asked by At

I'm experimenting with a Java client to store spatial data in MongoDB, however I'm hitting the exception:

org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.vividsolutions.jts.geom.Point.

I guess my Java client doesn't include a codec for the JTS classes. I thought such a library would exist as it seems like a fairly common thing to want to do. I haven't found anything that is obviously (to me at least) what I'm looking for.

Does such a thing exist? If so, is there a dependency I can add to my pom.xml file to include this functionality? Or do I have to write my own codec?

Thanks

1

There are 1 best solutions below

2
On BEST ANSWER

GeoTools provides an unsupported mongodb-plugin which should provide this functionality. You need to add

<dependency>
   <groupId>org.geotools</groupId>
   <artifactId>gt-mongodb</artifactId>
   <version>${geotools.version}</version>
 </dependency>

to your pom and add the following repository.

  <repository>
      <id>osgeo</id>
      <name>Open Source Geospatial Foundation Repository</name>
      <url>http://download.osgeo.org/webdav/geotools/</url>
  </repository>

Note this is an unsupported module so it may be lacking documentation and functionality. So feedback on the user list would be helpful and PRs most useful.