Can you not use gis.content.add() with *.shp but only *.zip?

812
1
01-25-2019 03:09 PM
Arne_Gelfert
Regular Contributor

I was reading the following as a convenience feature:

If you have a small amount of data in a shapefile, you can make it available for others to view through a web browser by adding it as a .zip file containing the .shp.shx.dbf, and .prj files to a map you create with Map ViewerShapefiles—Portal for ArcGIS | ArcGIS Enterprise 

But it looks like the following really doesn't work:

county_properties = {'title':'Active Counties',
                     'tags':'counties, rigs, portal upload test',
                     'type':'Shapefile'}
counties_shp = mygis.content.add(county_properties, data='c:/temp/counties.shp')
Error while analyzing Shapefile 'counties.shp' Invalid Shapefile

Then, however, I can do this:

import zipfile
import glob, os

shpDir = 'c:/temp'
nametrunc = 'counties*'

files = glob.glob(os.path.join(shpDir,nametrunc))

with zipfile.ZipFile(os.path.join(shpDir,'counties.zip'), 'w') as myzip:
   for file in files:
     myzip.write(file)

counties_shp = mygis.content.add(county_properties, data='c:/temp/counties.zip')

I haven't had to upload a bunch of SHP files to Portal but it sure would be easier if you didn't have to zip them up.

0 Kudos
1 Reply
DanPatterson_Retired
MVP Esteemed Contributor

Makes sense to me since the shp portion of a shapefile is only one component.  zipping the 'shapefile' makes sure all the bits are moved on