Skip to content

Instantly share code, notes, and snippets.

@nommuna2
nommuna2 / Sample.js
Last active April 26, 2019 21:09
(ArcGIS API for JavaScript) Sample of putting a third party chart API in a popup
require([
"esri/Map",
"esri/views/MapView",
"esri/PopupTemplate",
"esri/layers/FeatureLayer",
"esri/widgets/Popup",
"esri/tasks/support/Query",
"https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.js",
"dojo/domReady!"
],
@nommuna2
nommuna2 / sample.py
Last active April 26, 2019 21:06
(Arcpy and ArcGIS API for Python) Automation of sd files and then publishing them to ArcGIS Enterprise
import arcgis
from arcgis.gis import GIS
import arcpy
import os
def createSDFiles():
workSpace = 'C:/sdFiles/'
arcpy.env.workspace = workSpace
fileList = os.listdir(workSpace)
@nommuna2
nommuna2 / sample.py
Last active April 26, 2019 21:04
(ArcGIS API for Python) Update service definition in AGOL
import arcgis
from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
# Log into AGOL account [admin level]
gis = GIS(None,'username', 'password', verify_cert=False)
# Grab the feature layer item by id
featureLayerItem = gis.content.get('feature layer id')
@nommuna2
nommuna2 / Sample.py
Last active April 26, 2019 21:04
(ArcGIS API for Python) Sample of exporting a Feature layer to a file GeoDatabase using Python API
import arcgis
import json
from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
# Log into AGOL account [admin level]
gis = GIS(None,'username', 'password', verify_cert=False)
# Grab the feature layer item by id
featureLayerItem = gis.content.get('feature layer id')
@nommuna2
nommuna2 / Sample.py
Last active April 26, 2019 21:03
(ArcGIS API for Python) Deleting all content from a user [Python API]
import arcgis
import json
from arcgis.gis import GIS
gis = GIS(None,'username', 'password', verify_cert=False)
#This function takes in a username and a item [type] for deletion
def deleteContent(owner, itemType):
try:
@nommuna2
nommuna2 / Sample.py
Last active April 26, 2019 21:01
(ArcGIS API for Python) Sample of downloading feature services from AGOL
import arcgis
import json
from arcgis.gis import GIS
gis = GIS(None,'username', 'password', verify_cert=False)
# Download all data from a user
def downloadUserItems(owner, downloadFormat):
try:
#Search items by username
@nommuna2
nommuna2 / Sample.js
Last active April 26, 2019 21:00
(ArcGIS API for Python) Make items authoritative in AGOL
import arcgis
from arcgis.gis import GIS
import requests
gis = GIS(None,'username', 'password', verify_cert=False)
try:
featureLayerItem = gis.content.get('item id')
r = requests.post('https://{0}/sharing/rest/content/items/{1}/setContentStatus'.format('org domain',featureLayerItem.id), data= {'status': 'org_authoritative','clearEmptyFields': 'false', 'f':'json', 'token': 'token'})
print(r)
@nommuna2
nommuna2 / FeatureLayerSample.py
Last active April 26, 2019 20:59
(ArcGIS API for Python) Copying metadata from an existing service to a new item through a REST endpoint using the Python API
#Using a feature layer
import arcgis
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
gis = GIS()
# Use the FeatureLayer class to get item from an service endpoint
url = 'https://idpgis.ncep.noaa.gov/arcgis/rest/services/NWS_Climate_Outlooks/cpc_6_10_day_outlk/MapServer'
layer = FeatureLayer(url)
@nommuna2
nommuna2 / SpatialFilterSample.js
Last active April 26, 2019 20:56
(ArcGIS API for JavaScript) Two samples of how to get the points within a certain polygon
// This sample uses the server to find if any points are within a certain polygon.
// This option only uses one for loop to go through each polygon and then uses a spatial filter as input to the query for the points.
// For this option your points would need to be on the server either through a map service or a feature layer.
require(["esri/map",
"esri/layers/FeatureLayer",
"esri/tasks/query",
"esri/tasks/QueryTask",
"esri/geometry/geometryEngine",
"esri/graphic",
@nommuna2
nommuna2 / Sample.py
Last active April 26, 2019 20:54
(ArcGIS API for Python) Sample of adding an item to AGOL,publishing, overwriting, and updating
#Adding an item to AGOL and publishing it
csv = r'path to csv'
csvItem = gis.content.add({}, csv)
csvFeatureLayer = csvItem.publish()
#Overwriting a service
#Search for the FeatureService by name
MyFeatureService = gis.content.search(query='title:SampleTest AND owner:owner')
#Get the id related to the Feature Service