janderssn / postgis-java-ng

PostGIS Java bindings (Next Generation)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PostGIS Java bindings (Next Generation)

Build Status Maven Central javadoc License

Lines of Code Security Rating Reliability Rating Maintainability Rating

This project contains Java bindings for using PostGIS geometries coming from a PostgreSQL database.

This project is based on postgis-java and first of all I want to thank its authors for their work.

Project goals and improvements to the existing postgis-java:

  • Support for geometries containing arcs like CIRCULARSTRING or CURVEPOLYGON
  • Support for PostGIS geography datatype
  • Use generic Java types where possible and simplify/streamline API
  • Clean up code to basically only work on WKB/EWKB implementations to reduce code duplication and focus on the actual database format
  • Support for the latest PostgreSQL (9.6+) and PostGIS versions (2.3+)
  • Support for JDK 8+
  • The license is still LGPL

Supported geometry types:

  • Point
  • LineString
  • CircularString
  • CompoundCurve
  • Polygon
  • CurvePolygon
  • MultiPoint
  • MultiLineString
  • MultiCurve
  • MultiPolygon
  • MultiSurface
  • GeometryCollection

How to use it

There is a Maven artifact in the official Maven repository, so just add this to your Maven POM:

<dependency>
	<groupId>io.github.sebasbaumh</groupId>
	<artifactId>postgis-java-ng</artifactId>
	<version>1.3.1</version>
</dependency>

The API differs a bit from postgis-java with the main point being a different namespace (io.github.sebasbaumh.postgis) as publishing a project to Maven Central requires to own that namespace. In addition the class structure is a bit different (see below) to support arc geometries and reduce boilerplate code, but you should be able to adapt to it easily. The implementations of the parser and writer for the geometries have been heavily reworked to speed up processing and reduce complexity.

Hierarchy of geometry classes:

Hierarchy of geometry classes

How to run tests utilizing a PostgreSQL server

You will need a PostgreSQL server with installed PostGIS extension for some of the tests.

In this example the server is named MyServer and the database UnitTestDB. The database can be empty except installing the PostGIS extension.

You should set up a database user for the unit tests, which has access rights to this database and only to this one. In this example the user is called unittest and has the password CHANGEME.

To run the unit tests accessing the server, add the following to your VM arguments (eclipse Run Configuration->Arguments->VM arguments):

-DtestJdbcUrl="jdbc:postgresql://MyServer/UnitTestDB" -DtestJdbcUsername="unittest" -DtestJdbcPassword="CHANGEME"

Or add the following Maven build parameters to the launch configuration in eclipse:

Parameter Name Value
testJdbcUrl jdbc:postgresql://MyServer/UnitTestDB
testJdbcUsername unittest
testJdbcPassword CHANGEME

There are also local tests contained in the project, so you are still able to test most parts without specifying a PostgreSQL server. And the test console output will show if tests were run with or without a database.

About

PostGIS Java bindings (Next Generation)

License:GNU Lesser General Public License v3.0


Languages

Language:Java 100.0%