ArcGIS API for Python - geometry.project

1362
1
Jump to solution
07-31-2018 10:47 AM
KarstenRank
Occasional Contributor III

Hi to all,

I tried this script with ArcGIS API from Python 1.4.2 like arcgis.geometry module — arcgis 1.4.2 documentation .

from arcgis.gis import GIS

from arcgis import geometry

input_geom = [{"x": -17568824.55, "y": 2428377.35}, {"x": -17568456.88, "y": 2428431.352}]

result = geometry.project(geometries = input_geom, in_sr = 3857, out_sr = 4326)

I get this error:


--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-8-a89d8e1c23f7> in <module>() ----> 1 result = geometry.project(geometries = input_geom, in_sr = 3857, out_sr = 4326, ) C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\geometry\functions.py in project(geometries, in_sr, out_sr, transformation, transform_foward, gis) 646 if gis is None: 647 gis = arcgis.env.active_gis --> 648 return gis._tools.geometry.project( 649 geometries, 650 in_sr, AttributeError: 'NoneType' object has no attribute '_tools'


What I'm doing wrong?

Thanks Karsten

0 Kudos
1 Solution

Accepted Solutions
ChristinaMosnick
New Contributor II

It looks like you need to connect to a GIS first.  This worked for me:

from arcgis.geometry import project
from arcgis.gis import GIS

# This is the line you're missing
gis = GIS()
input_geoms = [{"x": -17568824.55, "y": 2428377.35}, {"x": -17568456.88, "y": 2428431.352}]
result = project(geometries=input_geoms, in_sr=3857, out_sr=4326)
result

View solution in original post

1 Reply
ChristinaMosnick
New Contributor II

It looks like you need to connect to a GIS first.  This worked for me:

from arcgis.geometry import project
from arcgis.gis import GIS

# This is the line you're missing
gis = GIS()
input_geoms = [{"x": -17568824.55, "y": 2428377.35}, {"x": -17568456.88, "y": 2428431.352}]
result = project(geometries=input_geoms, in_sr=3857, out_sr=4326)
result