Possible to get Feature Layer/Tile Layer Storage Size with the ArcGIS API for Python

932
7
02-13-2019 08:48 AM
PatrickFilyer
Occasional Contributor II

Would this be possible?

If so, can someone provide an example. 

Thanks

7 Replies
NikolajGrønholdt
Esri Contributor

Yes, it is possible. I've posted an example below.

import arcgis

url = "your organization url"
username = " your username"
password = "your password"
item_name = "feature name"

gis = arcgis.gis.GIS(url, username, password)
item = gis.content.search(item_name)[0]
item_id = gis.content.get(item.id)
item_size = item_id.size/1024/1024

print(item_size)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

The above show the result in MB. If you want to print the size in bytes, just remove the two divisions in item_size.

PatrickFilyer
Occasional Contributor II

Thank you very much

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Just a note of caution, the provided code will not always produce accurate sizes for GIS services in Portal.  I have found that when a GIS service is hosted in a data store tied to one of the additional GIS server roles, e.g., spatiotemporal data store registered with GeoAnalytic Server, the size is returned as 0 or some very small number that likely represents metadata size and not actual data size.

PatrickFilyer
Occasional Contributor II

Thanks, I will keep this in mind. 

0 Kudos
NikolajGrønholdt
Esri Contributor

Thank you for the heads up Joshua. I was not aware of that.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Esri's documentation on the size of items in Portal is missing quite a few important footnotes.  At best, the documentation is misleading.

When an item is loaded into Portal, a item.pkinfo file is created along with other files.  The file holds metadata about what is being loaded into Portal, including size information.  I haven't dove into the weeds enough to know whether Portal is creating the file or the client creates it and passes it to Portal, but I think the latter.

For GIS services hosted in Portal, e.g., feature layer, map image layer, etc..., Portal does not communicate with the data stores to determine the size of the GIS service.  The size value that shows up in Portal and through REST appears to be nothing more than what is recorded in item.pkinfo.  If a GIS service is created by uploading another file to Portal, like creating a feature layer from service definition file, the size value for the GIS service is inherited from the size value from the service definition file.

For tools that create a GIS service directly without uploading a file to Portal first, like Copy to Data Store with GeoAnalytic Server, there is no size value to inherit so it seems to get set to -1 which gets converted to 0 KB.

Data size can be tricky if one wants to split hairs.  The same data set stored as a shape file will be larger than when stored as a feature class in a file geodatabase, and a feature class in a file geodatabase can be smaller or larger on different systems depending on cluster sizes of file systems.

For GIS services hosted in Portal, the important take home is that the reported size information does not reflect the physical size of that service in the data store.  At best, the size value returned approximates the size of the GIS service in the data store, and at worst it is simply wrong.

0 Kudos
GISUser17
New Contributor

The above code works for an individual user within an organisations account.

I have modified the code to return all layers belonging to an individual user i.e. myself.

Is it possible to return the sizes for all users and their layers as well?

Thanks very much.

Richard.

0 Kudos