TransWikia.com

How to save/import .shp file data to a PostGIS table in Java

Geographic Information Systems Asked by eLowe on March 30, 2021

Ok, I’ve searched and at a loss as to why I cannot find anything on how to save a shapefile to PostGIS with Java. Thought GeoTools might be helpful, but doesn’t seem to be there either.

So here’s the scenario and functionality that I’ve been looking for.

  1. User uploads a file
  2. Java code (Spring) on the server side get the file and checks to see if it is a .shp file
  3. If it is a .shp file, save it to a PostGIS table

It’s step 3 that doesn’t seem to be out there and what I’d like to find a solution for. In my case the table will have all necessary fields and a couple of other fields to record who uploaded and when etc..

One Answer

Basically, you need a ShapefileDatastore to import your shapefile (remember to make sure you have at least 4 files and upto 13 at last count) then you create a PostGISDatastore to write the features from the first store to.

You will need to include gt-shapefile and gt-jdbc-postgis in your pom.xml. Then if you study this tutorial you will see how reading and writing features works.

If you are in a hurry, you can probably cut and paste from this answer.

Answered by Ian Turton on March 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP