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

01-25-2019 03:09 PM
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',
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,''), 'w') as myzip:
   for file in files:

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

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
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