Extract Spatial Reference of Shapefile Using API for Python

678
2
Jump to solution
02-23-2023 10:04 AM
by Anonymous User
Not applicable

Hello Esri Community,

I'm working on a project where a user submits a shapefile to a website and among other things, the spatial reference of that shapefile will be stored. 

Is there any way I can extract the spatial reference of that submitted shapefile? Since we're not using ArcMap nor ArcPro, we can't use arcpy unfortunately - It must be done through API for Python.

Attached below is a sample zipped shapefile that I'm currently working on.

Any help on this is greatly appreciated! 

Regards,

Mina

 

 

0 Kudos
2 Solutions

Accepted Solutions
Clubdebambos
Occasional Contributor III

Hi @Anonymous User 

The below assumes the shapefile is available in AGOL.

Clubdebambos_0-1677231592173.png

Use the shapefile item id

Clubdebambos_1-1677231650908.png

 

from arcgis.gis import GIS

## connect to agol
agol = GIS("Your AGOL URL", "username", "password")

## access the shapefile item
item = agol.content.get("shapefile_item_id_in_agol")

## print the spatial reference
print(item["spatialReference"])

 

 

~ learn.finaldraftmapping.com

View solution in original post

0 Kudos
JamesCrandall
MVP Frequent Contributor

Isn't the projection info found in the SitesForDemo_NAD83_Snapped.prj file that's packaged up in the zip file? I guess without arcpy you would have to temporarily unzip that file and read thru it to locate: PROJCS ["NAD_1983_2011_UTM_Zone_11N"

 

However, there's nothing that says/guarantees that what is being uploaded will contain that .prj file and you would have to handle that in your code.

View solution in original post

2 Replies
Clubdebambos
Occasional Contributor III

Hi @Anonymous User 

The below assumes the shapefile is available in AGOL.

Clubdebambos_0-1677231592173.png

Use the shapefile item id

Clubdebambos_1-1677231650908.png

 

from arcgis.gis import GIS

## connect to agol
agol = GIS("Your AGOL URL", "username", "password")

## access the shapefile item
item = agol.content.get("shapefile_item_id_in_agol")

## print the spatial reference
print(item["spatialReference"])

 

 

~ learn.finaldraftmapping.com
0 Kudos
JamesCrandall
MVP Frequent Contributor

Isn't the projection info found in the SitesForDemo_NAD83_Snapped.prj file that's packaged up in the zip file? I guess without arcpy you would have to temporarily unzip that file and read thru it to locate: PROJCS ["NAD_1983_2011_UTM_Zone_11N"

 

However, there's nothing that says/guarantees that what is being uploaded will contain that .prj file and you would have to handle that in your code.