Skip to content

Instantly share code, notes, and snippets.

@nommuna2
nommuna2 / Readme.md
Last active May 17, 2019 22:16
(ArcGIS API for JavaScript) Custom GL layer for a Feature Layer
@nommuna2
nommuna2 / Sample.py
Last active April 26, 2019 20:20
(ArcGIS API for Python) Publish a feature layer from server to AGO idea
# Sample of how to copy a feature layer from a local ArcGIS server and publish it to AGOL.
import arcgis
from arcgis import features
from arcgis import GIS
from arcgis.gis import Item
import json
gis = GIS(username="username", password= "password")
#Turn Feature Layer to a Feature Set
@nommuna2
nommuna2 / Sample.py
Last active April 26, 2019 20:22
(ArcGIS API for Python) Delete fields from a feature layer using the python API
import arcgis
from arcgis.gis import GIS
# Provide credentials to the GIS object.
gis = GIS(username="username", password= "password")
#Get the id of the hosted feature layer
item = gis.content.get("id of feature layer")
#Get the feature layer itself
@nommuna2
nommuna2 / Sample.js
Last active April 26, 2019 20:24
(ArcGIS API for JavaScript) Sample of adding popupTemplate to a mapservice layer in 3.x.
require(["esri/map",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/tasks/query",
"esri/tasks/QueryTask",
"esri/dijit/Popup",
"dojo/dom-construct",
"esri/dijit/PopupTemplate",
"dojo/domReady!"
], function (Map, ArcGISDynamicMapServiceLayer,Query, QueryTask, Popup, domCon, PopupTemplate) {
@nommuna2
nommuna2 / Sample.js
Last active April 26, 2019 20:41
(ArcGIS API for JavaScript 4.x) Sample of applying a definition expression on a feature layer using a drop-down.
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"dojo/domReady!"
],
function (Map, MapView, FeatureLayer) {
const filter = document.getElementById('state');
//Create a new map and set the basemap to Dark gray
@nommuna2
nommuna2 / Readme.md
Last active December 25, 2023 16:42
(ArcGIS API for JavaScript) Add Shapefile from disk to a map in 4.x
@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
@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 / 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 / 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)