Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manual operation bottleneck in uploading .shp files into the database #156

Open
tommasosansone91 opened this issue Jul 7, 2024 · 1 comment
Labels
question Further information is requested

Comments

@tommasosansone91
Copy link

as far as I can understand, geoserver-rest gives us a simple way to upload raster files in geoserver :

geo.create_coveragestore(
	layer_name='my-raster1', 
	path=r'data/raster/raster1.tif', 
	workspace='demo')

with this command, we indicate the file path of the raster we want to load, then we decide its layer name and the target workspace, and the file is uploaded in that workspace, with that layer name.

but when it comes to upload shape files in geoserver, it is more difficult:

we need 2 commands, one to create and one to publish the shape file

geo.create_featurestore(
	store_name='postgis', 
	workspace='demo', 
	db='postgres', 
	host='localhost', 
	pg_user='postgres', 
	pg_password='password')
 
geo.publish_featurestore(
	workspace='demo', 
	store_name='postgis', 
	pg_table='jamoat-db')

but before of that, we must manually load the .shp file into the database by using the wizard tool of postgis in postgres UI client (pgadmin).

this is a bottleneck, because it means that this process cannot be entirely automatized via python.

Would it be possible to extend the geoserver-rest library so that this step (manually load the .shp file into the database) is also managed via python?

I am willing to give my contribute to extend geoserver-rest and go past this issue.

@iboates
Copy link
Collaborator

iboates commented Jul 8, 2024

If I am understanding correctly, you want to start with a shapefile, then load it into a PostGIS database, and then publish the table in the database as a layer?

Loading a shapefile into a PostGIS database requires that you use a database connector, e.g. sqlalchemy. Geoserver-rest is an API client for interaction with Geoserver, so in my opinion, doing database manipulations is not within the scope of the library.

If you want to just upload and publish a shapefile directly, you should be able to do it with .create_shp_datastore

If you absolutely want to go from shapefile to PostGIS table first, then I would recommend using geopandas to load the shapfile into a GeoDataFrame, then loading it into PostGIS and using .publish_featurestore as normal. This guide explains how to open and load a shapefile with geopandas: https://hatarilabs.com/ih-en/how-to-upload-shapefiles-to-postgis-with-python-geopandas-and-sqlalchemy-tutorial

@iamtekson iamtekson added the question Further information is requested label Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants