Skip to content

Repository which demonstrates the integration of Timescale and PostGIS in a Spring Boot application.

License

Notifications You must be signed in to change notification settings

F3lixP4lm/Spring-Timescale-PostGIS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring-Timescale-PostGIS

Repository which demonstrates the integration of Timescale and PostGIS in a Spring Boot application.

Implementation also works with standard PostGIS Docker Image, replace f.e. postgis/postgis:14-3.2-alpine in the docker-compose file.

Connection

The database connection is configured within the application.yml

After starting the container and successfully configuring the database, the Spring application connects to the database immediately after startup.

SwaggerUI

With the help of Swagger, which is available after launching the Spring application, the application can be tested.

Link: http://localhost:8080/swagger-ui/index.html

Configuration

Between TestObjectDTO and TestObject the transformation of the coordinates differs.

The coordinates entered as latitude/longitude are transformed within the service into a point that can be stored by PostGIS.

private static final GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326);
[...]
 @Override
    public void addObject(TestObjectDTO dto) {
        Point p = factory.createPoint(new Coordinate(dto.getLatitude(),dto.getLongitude()));
        testObjectRepository.save(new TestObject(dto.getId(), p));
    }

When the object is queried, this Point variable is converted back to latitude/longitude format within the constructor of the TestObjectDTO.

public TestObjectDTO(TestObject object) {
        this.id = object.getId();
        this.latitude = object.getCoordinate().getX();
        this.longitude = object.getCoordinate().getY();
    }

About

Repository which demonstrates the integration of Timescale and PostGIS in a Spring Boot application.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages