Closed MengQiu-zl closed 1 year ago
Can you make sure the zip file contains all the required files (.shp, .shx, .prj, .dbf etc)? Also please verify that your data has some coordinate system before uploading.
The problem is that there is an extra level after decompressing my compressed package, resulting in no corresponding file found when publishing the service. The decompressed file should contain (. SHP,. SHX,. Prj,. DBF, etc). Thank you very much for your reply
@Qiumeng12 You can make the shapfile and all the supporting files to be zipped before using thecreate_shp_datastore
function. Inside the zipping function include all the possible extensions which may support the shapefile. After creating the shape datastore you can simply delete it using another function.
Below are the two functions. Please add if there are any more extensions to the array if there are missing ones I've mentioned.
def ZipShapeFiles():
extensions = [".shp",".shx",".dbf",".sbn",".sbx",".fbn",".fbx",".ain",".aih",".atx",".ixs",".mxs",".prj",".xml",".cpg",".shp.xml"]
filenames = ['buildings', 'roads', 'contours', 'water', 'militaryfence', 'land']
countfiles = len(filenames)
for x in range(0,countfiles):
inShp = "/geoserver-rest/input_files/"+ filenames[x] #location of zipping files
if exists(inShp + ".shp"):
inLocation = os.path.dirname (inShp)
inName = os.path.basename (os.path.splitext (inShp)[0])
zipfl = os.path.join (inLocation, inName + ".zip")
ZIP = zipfile.ZipFile (zipfl, "w")
for fl in os.listdir (inLocation):
for extension in extensions:
if fl == inName + extension:
inFile = os.path.join (inLocation, fl)
ZIP.write (inFile, fl)
break
def DeleteZips():
filenames = ['buildings', 'roads', 'contours', 'water', 'militaryfence', 'land']
countfiles = len(filenames)
for x in range(0,countfiles):
zipname = '/geoserver-rest/input_files/' + filenames[x] + ".zip"
if exists(zipname):
os.remove(zipname)
Hi @MengQiu-zl, I hope @MadaraPremawardhana solution worked for you. I am closing this issue since this is not related to this library.
I use the "create_shp_datastore" method to publish the datastore in a zip package, and the rest interface returns 202. What is the reason for this.