esri / arcgis-python-api Goto Github PK
View Code? Open in Web Editor NEWDocumentation and samples for ArcGIS API for Python
Home Page: https://developers.arcgis.com/python/
License: Apache License 2.0
Documentation and samples for ArcGIS API for Python
Home Page: https://developers.arcgis.com/python/
License: Apache License 2.0
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'] + ')')
ArcGIS for Server + Portal + DataStore version 10.5 beta.
Regards,
Mindaugas
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.
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.
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?
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
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
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.
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:
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.
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
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?
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'
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.
MacOS: 10.13.1
Python: 3.6.1
Jupyter: 4.4.0
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.
Any suggestion?
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.
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)
Any hope of getting Python updated to 3.6.x and conda to 4.3.x in ArcGIS Pro 2.0?
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:
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?ArcPy
is required for shape files?Thanks!
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
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?
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?
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:
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
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:
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?
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.
I am writing a script where I need to use the Export Item REST endpoint to export from a Feature Layer to a Feature Collection. As far as I can tell there doesn't seem to be a way to access Export Item via the ArcGIS Python API. (Or if there is, it doesn't seem to be documented.)
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.
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.
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
Here is the sample - > https://github.com/Esri/arcgis-python-api/blob/master/samples/05_content_publishers/publishing_web_maps_and_web_scenes.ipynb
{'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.
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"}
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.
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...., )?
Regards,
Mindaugas
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))
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?
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.)
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:
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...
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)?
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.
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?
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.
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/
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.
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]}
>>>
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
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.
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.
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'
>>>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.