Giter Site home page Giter Site logo

esri / arcgis-python-api Goto Github PK

View Code? Open in Web Editor NEW
1.8K 153.0 1.1K 2.9 GB

Documentation and samples for ArcGIS API for Python

Home Page: https://developers.arcgis.com/python/

License: Apache License 2.0

Python 100.00% Batchfile 0.01% PowerShell 0.01% Dockerfile 0.01%
arcgis gis spatial-data spatial-data-analysis data-science mapping python jupyter jupyterlab-extension

arcgis-python-api's Introduction

ArcGIS API for Python

ArcGIS API for Python is a Python library for working with maps and geospatial data, powered by web GIS. It provides simple and efficient tools for deep learning, sophisticated vector and raster analysis, geocoding, map making, routing and directions, as well as for organizing and managing a GIS with users, groups and information items. In addition to working with your own data, the library enables access to ready to use maps and curated geographic data from Esri and other authoritative sources. It also integrates well with the scientific Python ecosystem and includes rich support for Pandas, Scikit-Learn, Fast.ai, etc. and Jupyter notebook.

To learn more about the API, visit the product page here. You can get in touch with the developers of the API and other users like you at the community page here.

What's included

This SDK repository contains the following items:

  • API Reference Documentation. A hosted version of this can be found here.
  • Samples as Jupyter Notebooks.
  • Guides chapters as Jupyter Notebooks.
  • API Reference Documentation can be found here. Downloads are available for current and previous versions here.

You have multiple ways of executing these notebooks as listed below:

  • Execute locally on your computer by installing anaconda and the API. See Install and set up help Package managers
  • Execute with ArcGIS Pro. See the Install and set up ArcGIS Pro topic. For additional details, see Notebooks in ArcGIS Pro.
  • Execute with ArcGIS Notebooks, hosted on ArcGIS Online. Checkout this group with sample notebooks.
  • Execute in a Dockerised environment. See Install and set up help Installation as Docker image
  • Execute with Binder. See help here

Issues

Find a bug or want to request a new feature? Please let us know by submitting an issue. Thank you!

Contributing

Anyone and everyone is welcome to contribute. Please see our contribution guideline here.

Licensing

Copyright 2018-2022 Esri

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

A copy of the license is available in the repository's license.txt file.

arcgis-python-api's People

Contributors

1297rohit avatar achapkowski avatar akhilnegi avatar atmamani avatar cmpeng avatar davidjvitale avatar divyanshj16 avatar evamui avatar guneetmutreja avatar jtroe avatar jyaistmap avatar kapil-varshney avatar kgalliher avatar mayank2 avatar mohi9282 avatar moonlanderr avatar mpayson avatar nanaeaubry avatar nparavicini7 avatar priyankatuteja avatar qberto avatar rhea-j avatar rohitgeo avatar sdash77 avatar shub8703 avatar surajbaloni avatar tarunkukreja003 avatar vbhv14 avatar xlt208 avatar yongyao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arcgis-python-api's Issues

arcgis.viz MapView _handle_map_msg() incorrect number of arguments

Hi,

When using arcgis.viz MapView in a Jupyter Notebook, I have found that left click, hold and drag will move the map as desired, however on release an error is produced:

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
TypeError: _handle_map_msg() takes 3 positional arguments but 4 were given

If useful, this is my version and set-up:
Python 3.5.1 | Continuum Analystics, Inc. | (default, Jun 15 2016, 15:32:45)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux

Regards,

Bob

ArcGIS Python API (Beta) URLs and Content Causing Confusion

It turns out, quite a few of the ArcGIS Python API (Beta) URLs and Content are still alive and well. In and of itself, I don't think that would be an issue, but the URLs are basically the same as the current non-Beta URLs. Some users are stumbling onto the older URLs, but not realizing they are the older URLs, and they are getting confused with the examples and instructions that aren't working.

For example, Install and set up:
ArcGIS Python API (Beta)
https://developers.arcgis.com/python/guide/Install-and-set-up/

ArcGIS API for Python (1.0.1)
https://developers.arcgis.com/python/guide/install-and-set-up/

Notice, the only difference in the URLs is a capital "I" in the Beta URL. There are dozens and dozens of other examples I could provide.

The fact that the URLs are so similar, nearly identical, is tripping people up. I would recommend the Beta URLs either be shutdown completely or redirect to the current URL.

Add firstName, lastName, and userType to User.update method?

Frequently our AGOL organization needs to update the user attributes firstName, lastName, and userType (enabling/disabling Esri Access).

However, the arcgis python API's User.update method does not include parameters for these attributes.

Looking at the code, it appears that the User.update method is based off of portalpy's update_user method.

Can these attributes be added to the arcgis python API? If not, what would be the best way for me to extend the functionality of the arcgis python API?

Thanks!

Tim

Constructing Empty Geometries?

Looking at the arcgis.geometry documentation, I am unclear how to create empty geometries. I have tried numerous formats, and none generates an error, but they all say the polygons are invalid.

Am I missing something or are constructing empty geometries not supported?

Methods to find relationship info between items returns error

I'm encountering an issue when attempting to return a relationship between a Web Map and any layers found within it. The layers in the web map represent map services running off our ArcGIS Server.

Per the sample guide I've tried both the related_items and dependent_upon methods (https://developers.arcgis.com/python/guide/managing-your-content/#finding-relationships-between-items)

The following method returns an empty array:

import pandas as pd
from arcgis.gis import GIS
from IPython.display import display

gis = GIS('portal URL', 'username', 'password')

zoningLayer = gis.content.get('itemId')
zoningLayer

zoningLayer.related_items('Map2Service', 'forward')

The following method returns an error

zoningLayer.dependent_upon()

Error message

Unable to get dependencies for item: 84d75bd05f1d47f8a0266f8778c4498f
Unable to retrieve item dependencies.
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-4-c2f6af8c3606> in <module>()
----> 1 zoningLayer.dependent_upon()

/opt/conda/lib/python3.5/site-packages/arcgis/gis.py in dependent_upon(self)
   2993     def dependent_upon(self):
   2994         """ Returns items and urls, etc that this items depends upon  """
-> 2995         return self._portal.get_item_dependencies(self.itemid)
   2996 
   2997     def dependent_to(self):

/opt/conda/lib/python3.5/site-packages/arcgis/_impl/portalpy.py in get_item_dependencies(self, itemid)
   1124 
   1125     def get_item_dependencies(self, itemid):
-> 1126         return self.con.post('content/items/' + itemid + '/dependencies', self._postdata())
   1127 
   1128     def get_item_dependents_to(self, itemid):

/opt/conda/lib/python3.5/site-packages/arcgis/_impl/connection.py in post(self, path, postdata, files, ssl, compress, is_retry, use_ordered_dict, add_token, verify_cert, token)
    954                 elif errorcode == 498:
    955                     raise RuntimeError('Invalid token')
--> 956                 self._handle_json_error(resp_json['error'], errorcode)
    957                 return None
    958         except AttributeError:

/opt/conda/lib/python3.5/site-packages/arcgis/_impl/connection.py in _handle_json_error(self, error, errorcode)
    974 
    975         errormessage = errormessage + "\n(Error Code: " + str(errorcode) +")"
--> 976         raise RuntimeError(errormessage)
    977 
    978 class _StrictURLopener(request.FancyURLopener):

RuntimeError: Unable to get dependencies for item: 84d75bd05f1d47f8a0266f8778c4498f
Unable to retrieve item dependencies.
(Error Code: 500)

What are the limitations of these methods? Do they not work if any of the layers are hosted on a public ArcGIS Server?

CSS issue when running Jupyter in https://

We are running Jupyter Hub on a server, and the Jupyter url is an https:// url.

When the ArcGIS Python API loads, it runs, but interactive map results don't render properly because the map widget is unable to load the CSS because the python API code references http:// and the browser blocks the mixed content because of the https:// session.

Relevant errors below (with url redacted):

Mixed Content: The page at 'https://****' was loaded over HTTPS, but requested an insecure stylesheet 'http://js.arcgis.com/3.17/esri/css/esri.css'. This request has been blocked; the content must be served over HTTPS.

Mixed Content: The page at 'https://****' was loaded over HTTPS, but requested an insecure stylesheet 'http://js.arcgis.com/3.17compact/dijit/themes/claro/claro.css'. This request has been blocked; the content must be served over HTTPS.

Hyperlink to Constant References in API Documentation

In the areas_and_lengths documentation, it states:

If calculation_type is planar, then length_unit can be any esriUnits constant.

It would be really useful, handy even, if such references to "esriUnits constant" were actually hyperlinked to a listing and definition of those constants. Since most users won't have the constants memorized, having a hyperlink to the appropriate documentation for those constants saves users from having to go hunt for them.

Portal identity delegation from JS into Python

Below is more of a feature request than an issue:

I have a JS app that does a user login into AGOL (OAuth). If successful I want to call a python script that leverages Esri's ArcGIS Python API and manipulates content in the AGOL account. Problem is that the python is out of context so it needs to authenticate to AGOL too. I obviously don't want another login page and especially not a custom one, so how would I pass that security context over to the python code?

One approach I thought should have worked was in JS to grab the access token and then use that in the Python script. Problem is that the GIS class does not take a token as an argument:

class arcgis.gis.GIS(url=None, username=None, password=None, key_file=None, cert_file=None, verify_cert=True, set_active=True)

Any ideas how this might be accomplished?

Thanks.

areas_and_lengths Incorrect Default area_unit

According to the areas_and_lengths documentation:

If area_unit is not specified, then the units are meters.

Meters is not a valid areal unit. This appears to not just be a documentation issue but an actual code issue:

>>> from arcgis import gis, geometry
>>>
>>> gis = gis.GIS()
>>>
>>> geom_json = {
...     "rings": [[[0, 0], [0, 10], [10, 10],[10, 0],[0, 0]]],
...     "SpatialReference": {"wkid": 3857}
... }
>>>
>>> geom = geometry.Geometry(geom_json)
>>> geometry.areas_and_lengths(geom, "", "", "", 3857)
Error computing areas and lengths
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispython\lib\site-packages\arcgis\geometry\functions.py", line 85, in areas_and_lengths
    spatial_ref)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispython\lib\site-packages\arcgis\_impl\tools.py", line 4596, in areas_and_lengths
    return self._con.post(path=url, postdata=params, token=self._token)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispython\lib\site-packages\arcgis\_impl\connection.py", line 956, in post
    self._handle_json_error(resp_json['error'], errorcode)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispython\lib\site-packages\arcgis\_impl\connection.py", line 976, in _handle_json_error
    raise RuntimeError(errormessage)
RuntimeError: Error computing areas and lengths
(Error Code: 500)
>>> 
>>> # override default "meters" with "square meters"
>>> geometry.areas_and_lengths(geom,"", "esriSquareMeters", "", 3857)
{'areas': [100], 'lengths': [40]}
>>> 

'_GeometryService' object has no attribute 'areasAndLengths'

Can someone explain why I am seeing this error? Maybe I am misunderstanding the documentation, but I don't understand why this error is being raised.

>>> import arcgis
>>> from arcgis.gis import GIS
>>> from arcgis.geometry import Geometry
>>> 
>>> gis = GIS()
>>> 
>>> geom = Geometry({"rings":[[[0,0],[0,10],[10,10],[10,0],[0,0]],[[3,3],[7,3],[7,7],[3,7],[3,3]]],
...                  "spatialReference":{"wkid":26915}})
>>>
>>> arcgis.geometry.areas_and_lengths(geom, "", "", "", 26915)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Anaconda3\lib\site-packages\arcgis\geometry\functions.py", line 80, in areas_and_lengths
    return gis._tools.geometry.areasAndLengths(
AttributeError: '_GeometryService' object has no attribute 'areasAndLengths'
>>>

Copy a web map item

Hello,

We are considering to use Python API for one of our projects in order to automate work order creation. A possible scenario consists of copying an existing master template web map, renaming it with work order ID and maybe changing a few other settings. So this is basically what you can do manually in AGOL by clicking on "Save As" within the web map.

However, currently I cannot find a way to do that in the API. I use search function to find the web map item of interest and find it successfully. Intellisense is telling me that there is a method of "Item" class called "copy", although when I went to explore the "gis" python module directly in the Visual Studio, I could not find such a method. Is this method in development for the upcoming stable release? And if not, could anyone recommend me a way to achieve what I need?

Thank you,

Serj

edit_features method does not accept list of Features when trying to add Features to a Feature Service

In the documentation/comments it says:

adds - The array of features to be added.
updates - The array of features to be updateded.
deletes - string of OIDs to remove from service

Yet the function only accepts a list/array of dictionaries or a list/array of PropertyMaps when trying to add items. When trying to update Features, it handles this correctly.

layer.py line 533

if isinstance(adds, FeatureSet):
    params['adds'] = json.dumps([f.as_dict for f in adds.features],
                                default=_date_handler)
elif len(adds) > 0:
    if isinstance(adds[0], dict):
        params['adds'] = json.dumps([f for f in adds],
                                    default=_date_handler)
    elif isinstance(adds[0], PropertyMap):
        params['adds'] = json.dumps([dict(f) for f in adds],
                                    default=_date_handler)
    else:
        print('pass in features as dict or PropertyMap')
if isinstance(updates, FeatureSet):
    params['updates'] = json.dumps([f.as_dict for f in updates.features],
                                   default=_date_handler)
elif len(updates) > 0:
    if isinstance(updates[0], dict):
        params['updates'] = json.dumps([f for f in updates],
                                       default=_date_handler)
    elif isinstance(updates[0], PropertyMap):
        params['updates'] = json.dumps([dict(f) for f in updates],
                                       default=_date_handler)
    elif isinstance(updates[0], Feature):
        params['updates'] = json.dumps([f.as_dict for f in updates],
                                       default=_date_handler)
    else:
        print('pass in features as dict or PropertyMap')

I expected this function to accept a list of arcgis.features.Feature and process add those.

The workaround is to create a arcgis.features.FeatureSet from the original set of features like:

my_feature_layer.edit_features(adds=arcgis.features.FeatureSet(list_of_features_to_add))

Add support for bulk updating organization's content to use HTTPS

It is becoming increasingly important that organizations use HTTPS only for their content. However, this can be challenging for organizations that have been using HTTP or a mix of both.

The December release of ArcGIS Online introduced the ability to update HTTP layers in a web map to use HTTPS on a per map basis. There are also several tools available for updating HTTP layers in web maps - ago assistant and geojobe. Geojobe has the capability to do this in bulk for web maps I believe (not positive, but believe it's only web maps).

It would be ideal if there's a way to perform a bulk HTTP -> HTTPS update of an organization's content. There are many item types / organization resources that could have HTTP references that would need to be updated. I think this is something that could be built / evolved over time based on feedback, etc.

A good first stab might be update web maps (and any layer items referenced in the web maps). From there could expand to include apps (configurable apps, story maps, etc).

Any update functionality should also include a reporting mechanism so that the org admin can identify what needs to be updated before proceeding. Would also need to check for the validity of the HTTPS endpoint for any HTTP resources (all Esri hosted offerings support HTTPS. Same with most on-prem AGS instances now. Problematic areas are typically things like references to multimedia, OGC, CSV, etc).

cc @AtmaMani

Find items with exact title using content.search

Is it possible to restrict search results to exact matches by title?

My query is title:City_Boundaries and owner:username and the search is returning other "City_Boundary" matches and would like to restrict to exact matches.

FeatureSet.save() to CSV - TypeError

I have a FeatureSet that I would like to save to CSV. One approach I've tried is to use the FeatureSet save() method. Unfortunately, attempting to save as a CSV produces a >> error. (Saving as a JSON file works just fine.)

Works (JSON)

In [14]: feature_set.save('data_folder', 'my_data.json')
Out [14]: 'data_folder/my_data.json'

Does not work (CSV)

In [15]: feature_set.save('data_folder', 'my_data.csv')
Out [15]: 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<timed eval> in <module>()

/Users/markegge/anaconda3/envs/arcgis/lib/python3.6/site-packages/arcgis/features/feature.py in save(self, save_location, out_name)
    690                 # write the headers to the csv
    691                 for field in self.fields:
--> 692                     fields.append(field['name'])
    693                 csv_writer.writerow(fields)
    694 

TypeError: string indices must be integers

Using Python 3.6, ArcGIS API for Python version 1.2.0.

Issue installing with Python 3.6

When attempting to install the package with Python 3.6 as shown below:

anaconda_test/anaconda/bin/conda create -n arcgis_fresh3.6 python=3.6 anaconda
anaconda_test/anaconda/bin/conda install -n arcgis_fresh3.6 -c esri arcgis

I get the following error:

UnsatisfiableError: The following specifications were found to be in conflict:
  - arcgis -> python 3.4* -> openssl 1.0.1*
  - arcgis -> python 3.4* -> xz 5.0.5
  - python 3.6*
Use "conda info <package>" to see the dependencies for each package.

If I create a virtual environment using Python 3.5, it installs and works as expected.

If you use the latest anaconda releases it will default to Python 3.6 which is how I originally found this error. Only tested this issue on Mac x86_64 anaconda.

Documentation says it supports 3.5 or higher

The ArcGIS API for Python requires Python 3.5 or higher.

Map cannot be displayed in Jupyter Notebook

I do not have GIS desktop installed.
I used conda to install the API.
Python Version is 3.6.
OS: windows 10

I tried the follwing:

from arcgis.gis import GIS
my_gis = GIS()
my_gis.map()

No map can be displayed.

error when publishing Scene Layer Package

Hi,

I'm using the ArcGIS API for Python inside a Python Toolbox tool in ArcGIS Pro 2.0. Part of my process is to create a Web Scene Layer Package which I upload to ArcGIS Online without any problems. but when I try to use the publish() function to create the service I always get the following error:

Traceback (most recent call last): File "<string>", line 143, in execute File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 4708, in publish serviceitem_id = self._check_publish_status(ret, folder) File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 4951, in _check_publish_status raise Exception("No job id") Exception: No job id Failed to execute (Tool).

If I try to publish the package item manually from ArcGIS Online it all works just fine.

# Uploading scene layer file to ArcGIS online
slpk_properties = {'title': item_title,
                              'description': 'Scene Layer de la capa: ' + fc,
                              'tags': 'arcgis, bim',
                              'type': 'Scene Package'}

layer_scene_pkg_item = gis.content.add(item_properties=slpk_properties, data=sceneLayerPath)
arcpy.AddMessage("Scene Layer package uploaded to AGOL: " + sceneLayerPath)

layer_scene_hosted_service = layer_scene_pkg_item.publish()
arcpy.AddMessage("Scene Layer package published to AGOL: " + sceneLayerPath)

I'm using version 1.2.3 of the API.

Change the owner of an item

I would like do change owner of a item
I'm trying this way

gis = GIS(url, user, pass)

item = gis.content.get("itemid")
item.update(owner="newOwner")

Error:

update() got an unexpected keyword argument 'owner'

I also tried the following way

item["owner"] = "newOwner"
item.update(item_properties=item)   

But it did not work

Has anyone ever had to do this?

Map is not displayed in Jupyter notebook

MacOS: 10.13.1
Python: 3.6.1
Jupyter: 4.4.0
mapview_validation

I followed "Widget JavaScript Not Detected #10" but it doesn't work.

jupyter nbextension install --py --sys-prefix arcgis
jupyter nbextension enable --py --sys-prefix arcgis

Here is a screenshot before starting.
screenshot 2017-12-08 10 33 04

When trying to show a map...
screenshot 2017-12-08 10 37 44

Any suggestion?

take layer offline devlab

Creating a devlab per:

Lab Description
Take data offline using spatial dataframe Show how to query feature layers into a dataframe and then write to a shape file or fgdb. Converse of import data

A few questions:

  1. Should I skip the dataframe since the save function is on a feature_set? We could then leave it as a challenge to create the dataframe and maybe a simple operation on that dataframe?
  2. Can I save to a shape file or fgdb on a Mac, it says ArcPy is required for shape files?
  3. Should the initial service query return all features or only a subset?

Pushing here

Thanks!

@AtmaMani @jyaistMap

Arcpy needs to run within active ArcGIS Conda Environment

My issue started the same as #10, where it was saying

Widget Javascript not detected. It may not be installed properly. Did you enable the widgetsnbextension? If not, then run "jupyter nbextension enable --py --sys-prefix widgetsnbextension

I uninstalled and reinstalled both packages

conda uninstall -c conda-forge ipywidgets
conda uninstall -c esri arcgis

conda install -c conda-forge ipywidgets
conda install -c esri arcgis
jupyter nbextension enable --py --sys-prefix widgetsnbextension

but that made everything worse. I am now getting an error saying

arcpy must be run from inside the Conda environment, which ArcGIS
uses to manage the installation of Python.
You can access this environment by launching Python from the links inside the
"ArcGIS > ArcGIS Pro" Start Menu Group:
"Python Interactive Terminal" starts a Python session.
"Python Command Prompt" opens a Command Prompt window initialized with Conda.

Install without anaconda?

I just wanted to see if there is any way to install this module into an existing Python environment, without pulling in an entire distribution of Anaconda. Is there a standalone package available via pip, or any other alternatives?

How to configure proxy in API?

Hi,

I'm having trouble using the API because my network needs to configure the proxy.
I have not found any method in the API to configure my proxy.

Has anyone else had this problem yet?

Unnecessarily Requiring Arguments With Optional Parameters

I suspect what I say below applies to numerous modules, but I have only started poking around in arcgis.geometry module

I have found several functions in arcgis.geometry that unnecessarily require arguments when default parameters exist, buffer is one of them:

>>> from arcgis import gis, geometry
>>>
>>> gis = gis.GIS()
>>>
>>> geom = {
...     "rings": [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]],
...     "SpatialReference" : {"wkid": 3857}
... }
>>> pg = geometry.Polygon(geom)
>>>
>>> # call buffer passing arguments for non-default parameters
... geometry.buffer([pg], 3857, 100)
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
TypeError: buffer() missing 1 required positional argument: 'unit'
>>>
>>> # call buffer passing bogus argument for default parameters
... geometry.buffer([pg], 3857, 100, "")
[{"rings": [[[10.000100001692772, -100.67390000075102], [0, -100.67390000075102], [-8.715500000864267, 
-100.29080000147223], [-17.36479999870062, -99.14449999853969], [-25.881900001317263, 
-97.24359999969602], [-34.20199999958277, -94.60249999910593], ....,  [44.20199999958277, 
-94.60249999910593], [35.88190000131726, -97.24359999969602], [27.36479999870062, 
-99.14449999853969], [18.71559999883175, -100.29080000147223], [10.000100001692772, 
-100.67390000075102]]]}]
>>>

The buffer documentation states for unit:

If unit is not specified, the units are derived from bufferSR. If bufferSR is not specified, the units are derived from in_sr.

The documentation strongly implies unit is optional since it has a default value. Additionally, passing an empty string to unit and having the function work verifies that unit has a default value because an empty string doesn't mean anything in terms of units.

Other arcgis.geometry functions that run into this same issue are areas_and_lengths and lengths, there may be others.

In Python, it is not idiomatic to require arguments for optional parameters.

Case-sensitive username

Tried logging in to a customer's org and my credentials kept getting rejected. As a sanity check I made sure they worked in ArcGIS Online and ultimately realized the issue was capitalization in the username. Kind of a maddening issue as it was difficult to determine if my credentials were truly wrong after entering the same information over and over:

screen shot 2017-04-13 at 10 23 50 am
screen shot 2017-04-13 at 10 23 10 am

Unless there's a benefit I'm missing, case-sensitivity seems like a bug when it comes to usernames. ArcGIS Online converts usernames to lower case right?

Sample Script Failing to Copy Item

Tried utilizing the clone_portal_users_groups_and_content.ipynb sample, but it continues to fail when copying items. (Error Below). Also, there are a few places where it references sourceusers and later calls source_users, same with system_users and systemusers


AttributeError Traceback (most recent call last)
in ()
25
26 for folder in folders:
---> 27 target.content.create_folder(folder, user)
28 folder_items = user.items(folder['title'])
29 for item in folderitems:

C:\Program Files\ArcGIS\Pro\bin\Python\lib\site-packages\arcgis\gis.py in create_folder(self, folder, owner)
1663 else:
1664 owner_name = owner
-> 1665 if self._portal.get_folder_id(owner_name, folder) is None:
1666 return self._portal.create_folder(owner_name, folder)
1667 else:

C:\Program Files\ArcGIS\Pro\bin\Python\lib\site-packages\arcgis_impl\portalpy.py in get_folder_id(self, owner, folder_name)
2190 # Loop through each folder JSON object
2191 for fldr in resp['folders']:
-> 2192 if fldr['title'].upper() == folder_name.upper(): # Force both strings to upper case for comparison
2193 return fldr['id']
2194 return None # no such folder found for this owner

AttributeError: 'dict' object has no attribute 'upper'

Conflicting Sizes Returned From arcgis.gis.Item

I am trying to understand this behavior:

>>> import arcgis
>>>
>>> url = # url of Portal or Organizational AGOL
>>> username = 
>>> password = 
>>> item_name = # name of item for looking up size
>>> 
>>> gis = arcgis.gis.GIS(url, username, password)
>>> item = gis.content.search(item_name)[0] # assumes unique name so only 1 item returned
>>> type(item)
<class 'arcgis.gis.Item'>
>>> item.size
-1
>>> item_full = gis.content.get(item.id)
>>> type(item_full)
<class 'arcgis.gis.Item'>
>>> item_full.size
3850776
>>> 

If I retrieve an item using arcgis.gis.ContentManager.search, I get an arcgis.gis.Item object where the size is returned as -1. If I retrieve the exact same item using arcgis.gis.ContentManager.get, I get an arcgis.gis.Item object where the size is returned as 3850776, which just happens to be the correct size.

If search and get are both returning arcgis.gis.Item objects, why do the results for size differ?

I am going to anticipate a possible response and reply. If the answer is that search doesn't retrieve all of the items properties while get does, then I ask "why not?" And if the response to that is 'performance,' then at a minimum the documentation needs to clearly point this out.

GeoAnalyticsTools Invalid URL path to BigData features

Set up Portal 10.5 Beta with ArcGIS Python API on the same machine.
Trying to test GeoAnalyticsTools BigData sample on Jupyter Notebook
Configured BigData NYCTaxi data. URL: https://mportal.hnit-baltic.lt/arcgis/rest/services/DataStoreCatalogs/bigDataFileShares_bdfs2/BigDataCatalogServer/NYCTaxi

from arcgis.gis import GIS
from arcgis.viz import MapView
from arcgis.tools import GeoAnalyticsTools

gis = GIS("https://mportal.hnit-baltic.lt/arcgis/", "admin_user", "admin_pass")
gae = GeoAnalyticsTools("https://mportal.hnit-baltic.lt/arcgis/rest/services/System/GeoAnalyticsTools/GPServer", gis)
maxTip = gae.aggregate_points_by_bins("https://mportal.hnit-baltic.lt/arcgis/rest/services/DataStoreCatalogs/bigDataFileShares_bdfs2/BigDataCatalogServer/NYCTaxi", None, "5 Kilometers", "1 Weeks", "1 Months", "1/1/2014", "tip_amount MAX")

Returns: Invalid URL
See attached image.

Have tried other tools: describe_dataset, list_bigdata_datasets.
What is correct parameters in gae.aggregate_points_by_bins(in_points...., )?

jupyter_notebook_geoanalyticstools

Regards,
Mindaugas

Use arcgis-python-api in Spyder instead of Jupyter Notebook? Getting "Widget Javascript not detected."

I've seen several issues logged abou the "Widget Javascript not detected." warnings/errors when starting to use arcgis-python-api in Jupyter notebooks(Issues #10...). I can follow the instructions and get the following result:

image

However, when I try a similar setup, but run Spyder...

(C:\Users\username\Anaconda2) C:\Windows\system32>activate py35

(py35) C:\Windows\system32>jupyter nbextension enable --py widgetsnbextension
Enabling notebook extension jupyter-js-widgets/extension...
      - Validating: ok

(py35) C:\Windows\system32>spyder

I get...

image

Has anyone successfully run the arcgis python package from Spyder? If so, am I missing something? Or, is the arcgis package incompatible with Spyder (even using the IPython console within Spyder)?

Clone_items function results in 'request timed out' error with large hosted feature layer

I am trying to copy a hosted feature layer from one org to another by using two GIS objects. I noticed that the new hosted feature layer in the target org gets up to around 70,000 features and then the script fails and the item is deleted.

Is there a way to get around the time out error?

Here is the code I am running. The item is here and is shared publicly. http://nitro.mapsdevext.arcgis.com/home/item.html?id=deffecf7689043afb0a6858558ed06b5

from arcgis.gis import GIS

def clone_item(source_id, target_folder, source_gis, target_gis, copy_data=True, search_existing_items=False):
    item = [source_gis.content.get(source_id)]

    target_gis.content.clone_items(items=item,
                                   copy_data=copy_data,
                                   search_existing_items=search_existing_items)






if __name__ == "__main__":
    SOURCE_GIS = GIS("https://nitro.mapsdevext.arcgis.com")
    TARGET_GIS = GIS("org_url", "username", "password")

    clone_item(source_id="deffecf7689043afb0a6858558ed06b5",
               source_gis=SOURCE_GIS,
               target_gis=TARGET_GIS,
               copy_data=True,
               search_existing_items=True)

License information does not show in ArcGIS Pro Python Package Manager

When installing or selecting the ArcGIS Python API in the Python Package Manager of ArcGIS Pro (2.0.1)
and also previous versions), the "Terms and Conditions" list the API as a third-party package where license terms were not found. This should be corrected to refer to the Apache 2.0 license.

pythonpackagemanager_nolicense

Improve content.search by making query accept dictionary

Currently the query argument accepts search sting (e.g., GIS.content.search(query='owner:astrong_pnw AND type:Feature Service')). I think this would work a lot better as a dictionary (e.g., GIS.content.search(query={'owner': 'astrong_pnw', 'type': 'Feature Service'}).

Advantages:

  • More flexible if certain item fields are not included in the query (i.e., dictionaries can support None type, search stings cannot)

  • Can support lists that are important for item fields like tags (e.g., GIS.content.search(query={'tags': ['tag1', 'tag2', 'tag3']})

  • Generally more pythonic

Search string documentation: http://resources.arcgis.com/en/help/arcgis-rest-api/#/Search_reference/02r3000000mn000000/

JSON formatting issue with API sample, "Publishing web maps and web scenes"

Here is the sample - > https://github.com/Esri/arcgis-python-api/blob/master/samples/05_content_publishers/publishing_web_maps_and_web_scenes.ipynb

1 - Webmap Template JSON is formatted incorrectly The documentation provides the following webmap template JSON:
{'baseMap': {'baseMapLayers': [{'id': 'defaultBasemap',
    'layerType': 'ArcGISTiledMapServiceLayer',
    'opacity': 1,
    'title': 'World Topographic Map',
    'url': 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer',
    'visibility': True}],
  'title': 'Topographic'},
 'operationalLayers': [{'itemId': '',
   'layerType': '',
   'opacity': 1,
   'title': '',
   'url': '',
   'visibility': True}],
 'spatialReference': {'latestWkid': 3857, 'wkid': 102100},
 'version': '2.5'}

Using this template, I get JSON parsing errors. To fix the issues, I had to change all of the single quotes to double quotes and surround the True values with double quotes.

My Fix

This is the modified webmap JSON that works for me:

{"baseMap": {"baseMapLayers": [{"id": "defaultBasemap",
    "layerType": "ArcGISTiledMapServiceLayer",
    "opacity": 1,
    "title": "World Topographic Map",
    "url": "https://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer",
    "visibility": "True"}],
  "title": "Topographic"},
 "operationalLayers": [{"itemId": "fce0ca8972ae4268bc4a69443b8d1ef5",
   "layerType": "ArcGISMapServiceLayer",
   "opacity": 1,
   "title": "2012 USA Median Age (Mature Support)",
   "url": "http://server.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Median_Age/MapServer",
   "visibility": "True"}],
 "spatialReference": {"latestWkid": 3857, "wkid": 102100},
 "version": "2.5"}

Support/Implement __geo_interface__

I suggest adding __geo_interface__ support to arcgis.features and arcgis.geometry.

__geo_interface__ is "a GeoJSON-like protocol for geo-spatial (GIS) vector data." It follows a similar model/idea as NumPy's Array Interface. It was proposed or put forward in 2013, and more than a dozen geospatial Python applications (see Python Geo_interface applications) implement the protocol. The protocol allows for simple and efficient transferring of features and geometries between various geospatial Python packages.

ArcPy currently supports __geo_interface__ in its Geometry classes (it can be argued there is only partial support since the current implementation is broken in several ways). On a system with both ArcPy and Shapely installed, passing a geometry object from the former to the latter can be done efficiently with a single function call:

>>> import arcpy
>>> from shapely.geometry import shape
>>> 
>>> arc_polygon = arcpy.FromWKT('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
...                             arcpy.SpatialReference(3857))
... 
>>> arc_polygon.area
100.0
>>> 
>>> shapely_polygon = shape(arc_polygon)  # pass ArcPy geometry to Shapely
>>> 
>>> shapely_polygon.area
100.0
>>> shapely_polygon.buffer(1.0).area
143.13654849054595
>>>

Granted, there are numerous ways features and geometry objects can be passed between geospatial Python packages, but __geo_interface__ represents an established, open, well-adopted, and efficient means that should be supported within the ArcGIS Python API. Additionally, the protocol is lightweight and straightforward to implement.

Using Python Terminology (Not JSON) for Python Data Structures

In looking over the arcgis.geometry documentation, there are multiple references to "array of points" or "array of paths." All of the examples given in module documentation don't use Python arrays but Python lists.

It seems the documentation is using JSON terminology to describe Python data structures, which is confusing at best and incorrect at worst. Seeing the geometry constructors don't actually need Python arrays, it would be nice to have the documentation updated to use the appropriate Python terminology, whatever that may be (for example, I can pass nested tuples and it works just like nested lists, so the constructor obviously doesn't need a Python array, list, or tuple; but some type of abstract type like a Python sequence.)

Unable to view Web Map in collector gallery after adding map via API

The code I wrote to create copies of the existing map, successfully creates new copies which I can see in My Contents tab in ArcGIS Online. However, I am unable to view those in the Collector App Map Gallery (Collector v10.3.5 running on iOS) Would anyone have a clue why? Something I am missing in the json?

If I manually "Save As" using the same title format as in the script, within the web map viewer, the map is visible in the Map Gallery of Collector app. So its the script copy process that is wrong I think.

webmap = gis.content.search(query = 'title:PC_Test', item_type=None, sort_field='numViews', sort_order='desc', max_items=9999)

testmap = webmap[0]

web_map_dict = testmap.get_data(try_json=True)

x = 0
while x <= 5:
    title = "PC_Test_" + str(x)
    web_map_properties = {'title': title,
                         'type':'Web Map',
                         'snippet':'This web map copied from template',
                         'tags':'ArcGIS Python API PC Test',
                         'text':json.dumps(web_map_dict)}

    web_map_item = `gis.content.add(web_map_properties)`

    x += 1

MapView: setting height has no effect, map centered on the left side

One of the sample notebooks (https://github.com/Esri/arcgis-python-api/blob/master/samples/02_power_users_developers/using_geometry_functions.ipynb) shows that map height can be changed through map1.height = '650px'. However, this has no effect (tested on both the Esri live demo as well as local notebooks). Furthermore, the MapView class (https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.widgets.html#mapview) has no height attribute.

Additionally, maps seem to be always centered on the left side of the screen.

Code:

from arcgis.gis import GIS
gis = GIS()
map1 = gis.map("Central Park, New York", zoomlevel=9)
map1.height = "800px"
map1

Result:

arcgis_mapview_bug

Overwrite Python API

Hi there!
It's Raul, from Esri Spain. I have received a question in Geonet and I need some help.

A customer is trying to use the API to overwrite the content of a feature service using a shapefile. We tried to do that using the Item.Update (1,2) function but it didn't work. It updates the metadata but not the content itself, the function even returns True as you can see here:

pythonapi

Do you have any thoughts on that? Is this a bug? Should we use any other function? Item.publish maybe?

They can not use ArcREST because they have no ArcPy installed in the machine which is going to run the script.

Thanks in advance,
Raul

arcgis.tools.list_bigdata_datasets fails because manifest does not contain PATH and TYPE objects

Hello,
first of all method declaration:
def list_bigdata_datasets(self, server_path):
parameter SERVER_PATH should be renamed to DATA_STORE_NAME or similar, as it requires call:
gae.list_bigdata_datasets("bdfs2")
when original URL is: https://mportal.hnit-baltic.lt:6443/arcgis/admin/data/items/bigDataFileShares/bdfs2/manifest

I have manifest generated by ArcGIS Server (NYC Taxi sample data from training material). Manifest does not contain JSON objects TYPE and PATH, and thus method fails executing:
for dataset in res['datasets']:
print("/server/datastores/bigDataFileShares/" + server_path + '/' + dataset['path'] + ' ('+ dataset['type'] + ')')

NYC_Taxi_2015_manifest.zip

ArcGIS for Server + Portal + DataStore version 10.5 beta.

Regards,

Mindaugas

Widget JavaScript Not Detected

Trying to run the samples -

Configured the Jupyter Notebook environment via

%%sh
conda install -c conda-forge ipywidgets
conda install -c esri arcgis

Both of those installed fine

Enabled widgets via

%%sh
jupyter nbextension enable --py --sys-prefix widgetsnbextension

Enabling notebook extension jupyter-js-widgets/extension...
- Validating: OK

Then if I try to instantiate a sample map:

from arcgis.gis import GIS

gis = GIS()
map = gis.map('Seattle, WA', 6)
map

I get a JavaScript error: Widget Javascript not detected. It may not be installed properly. Did you enable the widgetsnbextension? If not, then run "jupyter nbextension enable --py --sys-prefix widgetsnbextension"

Non-ESRI widgets work fine in my other notebooks.

Change tags of the item

I'm trying to change the tags of an item as follows

tags = ['tag1', 'tag2']
item["tags"] = tags
item.update(item)

or

tags = ['tag1', 'tag2']
item["tags"] = tags
item.update(item_properties=item)

But it does not work

Slight GIS doc confusion

The GIS.map() documentation refers to a "map widget" but it seems it should say "MapView widget".

I'm new to Python and to arcgis-python-api, so it could be this is an acceptable convention, but it threw me and had me looking for a Map type somewhere to see what I could do with the returned object (and really I was looking for a MapView).

Worth updating?

Mapping and Visualization Guide doesn't cover how to use 3rd party basemaps in MapWidget

https://github.com/Esri/arcgis-python-api/blob/master/guide/09%20Mapping%20and%20visualization/Using%20the%20map%20widget.ipynb

The last entry in this notebook shows how to search for 3rd party basemaps, but it doesn't say how to set your mapwidget basemap to one of these. I suspect it isn't possible in the MapWidget class since the MapWidget.basemap property expects a string (like 'topo', 'gray', etc) rather than a webmap Item class.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.