from arcgis.gis import GIS
Objectives
- how to log in to the ArcGIS Online and NOAA GeoPlatform
- create a basic map
- search for and add ArcGIS Online or NOAA GeoPlatform layers (eclipse path, eclipse cities)
- download netcdf file from NCAR Thredds server (bonus if you can do all this from python) Datset page: https://thredds.ucar.edu/thredds/ncss/grid/grib/NCEP/NBM/CONUS/National_Blend_CONUS_20240405_1600.grib2/dataset.html -select variable “Total cloud cover @ Ground or water surface” -set Time Subset to “single time” and value “2024-04-08T18:00:00Z” -set Download format to “netcdf4-classic”
Final Download URL: https://thredds.ucar.edu/thredds/ncss/grid/grib/NCEP/NBM/CONUS/National_Blend_CONUS_20240405_1600.grib2?var=Total_cloud_cover_surface&north=57.098&west=-138.394&east=-59.022&south=19.215&horizStride=1&time=2024-04-08T18:00:00Z&&accept=netcdf4-classic 5) Upload to your JupyterHub file home 6) (in external geospatial python container) read National Blend of Models (NBM) GRIB2 sky cover data, select cells with sky cover less or equal to 25%, convert raster to vector polygons, export to file 7) Start jupyterhub with a the custom arcgis python image - https://itcoocean.2i2c.cloud/ - log in - bring your own image - 8) read file into feature collection, display on map 9) find cities that are within the good sky area 10) select a city, create a drive time area of 3 hours 11) Find cities outside the drive area
Let’s create a gis connection to the public ArcGIS Online
= GIS() agol
= agol.map()
m m
= agol.content.search(query="title: eclipse AND owner:NWS.FWD_noaa",
content ="Feature Layer",
item_type=15) max_items
= agol.content.search(query="id:80f6cd4b89734ec1adb541a789879727",
content ="Feature Layer",
item_type=15) max_items
content
[<Item title:"BLM NV Annular Solar Eclipse Duration Lines" type:Feature Layer Collection owner:s76moore@blm.gov_BLM_EGIS>]
= content[1] item
item
item.layers
[<FeatureLayer url:"https://services2.arcgis.com/C8EMgrsFcRFL6LrL/arcgis/rest/services/2024_Eclipse_Shapefiles/FeatureServer/0">,
<FeatureLayer url:"https://services2.arcgis.com/C8EMgrsFcRFL6LrL/arcgis/rest/services/2024_Eclipse_Shapefiles/FeatureServer/1">,
<FeatureLayer url:"https://services2.arcgis.com/C8EMgrsFcRFL6LrL/arcgis/rest/services/2024_Eclipse_Shapefiles/FeatureServer/2">,
<FeatureLayer url:"https://services2.arcgis.com/C8EMgrsFcRFL6LrL/arcgis/rest/services/2024_Eclipse_Shapefiles/FeatureServer/3">,
<FeatureLayer url:"https://services2.arcgis.com/C8EMgrsFcRFL6LrL/arcgis/rest/services/2024_Eclipse_Shapefiles/FeatureServer/4">,
<FeatureLayer url:"https://services2.arcgis.com/C8EMgrsFcRFL6LrL/arcgis/rest/services/2024_Eclipse_Shapefiles/FeatureServer/5">,
<FeatureLayer url:"https://services2.arcgis.com/C8EMgrsFcRFL6LrL/arcgis/rest/services/2024_Eclipse_Shapefiles/FeatureServer/6">,
<FeatureLayer url:"https://services2.arcgis.com/C8EMgrsFcRFL6LrL/arcgis/rest/services/2024_Eclipse_Shapefiles/FeatureServer/7">]
0].properties item.layers[
{
"currentVersion": 11.2,
"id": 0,
"name": "center",
"type": "Feature Layer",
"serviceItemId": "12d5ada7da474b0cb678a3b067e67011",
"cacheMaxAge": 30,
"displayField": "",
"description": "",
"copyrightText": "",
"defaultVisibility": true,
"editingInfo": {
"lastEditDate": 1708267630164,
"schemaLastEditDate": 1708267630164,
"dataLastEditDate": 1708267630164
},
"relationships": [],
"isDataVersioned": false,
"hasContingentValuesDefinition": false,
"supportsAppend": true,
"supportsCalculate": true,
"supportsASyncCalculate": true,
"supportsTruncate": true,
"supportsAttachmentsByUploadId": true,
"supportsAttachmentsResizing": true,
"supportsRollbackOnFailureParameter": true,
"supportsStatistics": true,
"supportsExceedsLimitStatistics": true,
"supportsAdvancedQueries": true,
"supportsValidateSql": true,
"supportsCoordinatesQuantization": true,
"supportsLayerOverrides": true,
"supportsTilesAndBasicQueriesMode": true,
"supportsFieldDescriptionProperty": true,
"supportsQuantizationEditMode": true,
"supportsApplyEditsWithGlobalIds": false,
"supportsMultiScaleGeometry": true,
"supportsReturningQueryGeometry": true,
"hasGeometryProperties": true,
"geometryProperties": {
"shapeLengthFieldName": "Shape__Length",
"units": "esriMeters"
},
"advancedQueryCapabilities": {
"supportsPagination": true,
"supportsQueryAttachmentsCountOnly": true,
"supportsPaginationOnAggregatedQueries": true,
"supportsQueryRelatedPagination": true,
"supportsQueryWithDistance": true,
"supportsReturningQueryExtent": true,
"supportsStatistics": true,
"supportsOrderBy": true,
"supportsDistinct": true,
"supportsQueryWithResultType": true,
"supportsSqlExpression": true,
"supportsAdvancedQueryRelated": true,
"supportsCountDistinct": true,
"supportsPercentileStatistics": true,
"supportsSpatialAggregationStatistics": true,
"supportedSpatialAggregationStatistics": [
"EnvelopeAggregate",
"CentroidAggregate",
"ConvexHullAggregate"
],
"supportsLod": true,
"supportsQueryWithLodSR": false,
"supportedLodTypes": [
"geohash"
],
"supportsReturningGeometryCentroid": false,
"supportsReturningGeometryEnvelope": false,
"supportsReturningGeometryProperties": true,
"supportsQueryWithDatumTransformation": true,
"supportsCurrentUserQueries": true,
"supportsHavingClause": true,
"supportsOutFieldSQLExpression": true,
"supportsMaxRecordCountFactor": true,
"supportsTopFeaturesQuery": true,
"supportsDisjointSpatialRel": true,
"supportsQueryWithCacheHint": true,
"supportedOperationsWithCacheHint": [
"query",
"queryTopFilter",
"queryAnalytics",
"queryAttachments",
"queryRelated",
"queryBins"
],
"supportsQueryAnalytic": true,
"supportsQueryBins": true,
"supportsDefaultSR": true,
"supportsFullTextSearch": true
},
"advancedQueryAnalyticCapabilities": {
"supportsLinearRegression": true,
"supportsAsync": true,
"supportsPercentileAnalytic": true
},
"queryBinsCapabilities": {
"supportsAsync": true,
"supportsAutoIntervalBin": true,
"supportsFixedIntervalBin": true,
"supportsFixedBoundariesBin": true,
"supportsDateBin": true,
"supportedStatisticTypes": [
"COUNT",
"SUM",
"AVG",
"VAR",
"STDDEV",
"MIN",
"MAX",
"PERCENTILE_CONT",
"PERCENTILE_DISC",
"CentroidAggregate",
"EnvelopeAggregate",
"ConvexHullAggregate"
]
},
"advancedEditingCapabilities": {
"supportedSqlFormatsInCalculate": [
"standard"
],
"supportsAsyncApplyEdits": true,
"supportsReturnEditResults": true,
"supportsApplyEditsbyUploadID": true,
"supportedApplyEditsUploadIDFormats": "JSON"
},
"infoInEstimates": [
"extent",
"count"
],
"useStandardizedQueries": true,
"geometryType": "esriGeometryPolyline",
"minScale": 0,
"maxScale": 0,
"extent": {
"xmin": -12241992.532475734,
"ymin": 2156468.869093142,
"xmax": -5254628.395448696,
"ymax": 6275361.962109568,
"spatialReference": {
"wkid": 102100,
"latestWkid": 3857
}
},
"drawingInfo": {
"renderer": {
"type": "simple",
"symbol": {
"type": "esriSLS",
"style": "esriSLSSolid",
"color": [
165,
83,
183,
255
],
"width": 1
}
},
"transparency": 0,
"labelingInfo": null
},
"allowGeometryUpdates": true,
"hasAttachments": false,
"htmlPopupType": "esriServerHTMLPopupTypeNone",
"hasM": false,
"hasZ": false,
"objectIdField": "FID",
"uniqueIdField": {
"name": "FID",
"isSystemMaintained": true
},
"globalIdField": "",
"typeIdField": "",
"fields": [
{
"name": "FID",
"type": "esriFieldTypeOID",
"actualType": "int",
"alias": "FID",
"sqlType": "sqlTypeInteger",
"nullable": false,
"editable": false,
"domain": null,
"defaultValue": null
},
{
"name": "Name",
"type": "esriFieldTypeString",
"actualType": "nvarchar",
"alias": "Name",
"sqlType": "sqlTypeNVarchar",
"length": 16,
"nullable": true,
"editable": true,
"domain": null,
"defaultValue": null
},
{
"name": "Time0",
"type": "esriFieldTypeString",
"actualType": "nvarchar",
"alias": "Time0",
"sqlType": "sqlTypeNVarchar",
"length": 16,
"nullable": true,
"editable": true,
"domain": null,
"defaultValue": null
},
{
"name": "Time1",
"type": "esriFieldTypeString",
"actualType": "nvarchar",
"alias": "Time1",
"sqlType": "sqlTypeNVarchar",
"length": 16,
"nullable": true,
"editable": true,
"domain": null,
"defaultValue": null
},
{
"name": "Shape__Length",
"type": "esriFieldTypeDouble",
"actualType": "float",
"alias": "Shape__Length",
"sqlType": "sqlTypeFloat",
"nullable": true,
"editable": false,
"domain": null,
"defaultValue": null
}
],
"indexes": [
{
"name": "Shape__Length_Index",
"fields": "Shape__Length",
"isAscending": true,
"isUnique": false,
"description": "",
"indexType": "Attribute"
},
{
"name": "PK__T_2024_E__C1BEA5A2220A2D62",
"fields": "FID",
"isAscending": true,
"isUnique": true,
"description": "clustered, unique, primary key",
"indexType": "Attribute"
},
{
"name": "user_14963.T_2024_ECLIPSE_SHAPEFILES_CENTER_Shape_sidx",
"fields": "Shape",
"isAscending": true,
"isUnique": false,
"description": "Shape Index",
"indexType": "Spatial"
}
],
"dateFieldsTimeReference": {
"timeZone": "UTC",
"respectsDaylightSaving": false
},
"preferredTimeReference": null,
"types": [],
"templates": [
{
"name": "New Feature",
"description": "",
"drawingTool": "esriFeatureEditToolLine",
"prototype": {
"attributes": {
"Name": null,
"Time0": null,
"Time1": null
}
}
}
],
"supportedQueryFormats": "JSON, geoJSON, PBF",
"supportedAppendFormats": "sqlite,geoPackage,shapefile,filegdb,featureCollection,geojson,csv,excel,jsonl,featureService",
"supportedAppendSourceFilterFormats": "sqlite,geoPackage,shapefile,filegdb,featureService",
"supportedExportFormats": "csv,shapefile,sqlite,geoPackage,filegdb,featureCollection,geojson,excel",
"supportedSpatialRelationships": [
"esriSpatialRelIntersects",
"esriSpatialRelContains",
"esriSpatialRelCrosses",
"esriSpatialRelEnvelopeIntersects",
"esriSpatialRelIndexIntersects",
"esriSpatialRelOverlaps",
"esriSpatialRelTouches",
"esriSpatialRelWithin",
"esriSpatialRelDisjoint",
"esriSpatialRelRelation"
],
"supportedContingentValuesFormats": "JSON, PBF",
"supportedSyncDataOptions": 4,
"hasStaticData": true,
"maxRecordCount": 2000,
"standardMaxRecordCount": 4000,
"standardMaxRecordCountNoGeometry": 32000,
"tileMaxRecordCount": 4000,
"maxRecordCountFactor": 1,
"capabilities": "Query"
}
= 0
i for l in item.layers:
print(i, l.properties["name"])
= i + 1 i
0 center
1 duration
2 ppath
3 ppath01
4 umbra_hi
5 umbra_lo
6 upath_hi
7 upath_lo
m
= item.layers[2] ppath_layer
={'opacity':0.3}) m.add_layer(ppath_layer, options
=[ppath_layer]) m.remove_layers(layers
True
= item.layers[7] upath_lo_layer
={'opacity':0.3}) m.add_layer(upath_lo_layer, options
In order to log in to the NOAA GeoPlatform, you need to create a “client_id”
= GIS("https://noaa.maps.arcgis.com",client_id="sidPYKs786TiwBcz") gis
Please sign in to your GIS and paste the code that is obtained below.
If a web browser does not automatically open, please navigate to the URL below yourself instead.
Opening web browser to navigate to: https://noaa.maps.arcgis.com/sharing/rest/oauth2/authorize?response_type=code&client_id=sidPYKs786TiwBcz&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&state=AHQXYrViZgxeyGsgFCYFBR9F6fNZ11
Enter code obtained on signing in using SAML: ············································································································································································································································
/opt/conda/lib/python3.8/site-packages/urllib3/connectionpool.py:1013: InsecureRequestWarning: Unverified HTTPS request is being made to host 'noaa.maps.arcgis.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
warnings.warn(
print("Successfully logged in as: " + gis.properties.user.username)
Successfully logged in as: Tim.Haverland_noaa
Geocode a point
from arcgis.geocoding import geocode
= geocode('Burlington, VT',as_featureset=True) results
results
<FeatureSet> 3 features
results.features
[{"geometry": {"x": -73.2109954, "y": 44.4759918, "spatialReference": {"wkid": 4326, "latestWkid": 4326}}, "attributes": {"Loc_name": "World", "Status": "T", "Score": 100, "Match_addr": "Burlington, Vermont", "LongLabel": "Burlington, VT, USA", "ShortLabel": "Burlington", "Addr_type": "Locality", "Type": "City", "PlaceName": "Burlington", "Place_addr": "Burlington, Vermont", "Phone": "", "URL": "", "Rank": 8.69, "AddBldg": "", "AddNum": "", "AddNumFrom": "", "AddNumTo": "", "AddRange": "", "Side": "", "StPreDir": "", "StPreType": "", "StName": "", "StType": "", "StDir": "", "BldgType": "", "BldgName": "", "LevelType": "", "LevelName": "", "UnitType": "", "UnitName": "", "SubAddr": "", "StAddr": "", "Block": "", "Sector": "", "Nbrhd": "", "District": "", "City": "Burlington", "MetroArea": "", "Subregion": "Chittenden County", "Region": "Vermont", "RegionAbbr": "VT", "Territory": "", "Zone": "", "Postal": "", "PostalExt": "", "Country": "USA", "CntryName": "United States", "LangCode": "ENG", "Distance": 0, "X": -73.2109954, "Y": 44.4759918, "DisplayX": -73.2109954, "DisplayY": 44.4759918, "Xmin": -73.2599954, "Xmax": -73.1619954, "Ymin": 44.4269918, "Ymax": 44.5249918, "ExInfo": "", "OBJECTID": 1}},
{"geometry": {"x": -73.21207, "y": 44.47588, "spatialReference": {"wkid": 4326, "latestWkid": 4326}}, "attributes": {"Loc_name": "World", "Status": "T", "Score": 100, "Match_addr": "Burlington, Vermont", "LongLabel": "Burlington, VT, USA", "ShortLabel": "Burlington", "Addr_type": "Locality", "Type": "City", "PlaceName": "Burlington", "Place_addr": "Burlington, Vermont", "Phone": "", "URL": "", "Rank": 13.72, "AddBldg": "", "AddNum": "", "AddNumFrom": "", "AddNumTo": "", "AddRange": "", "Side": "", "StPreDir": "", "StPreType": "", "StName": "", "StType": "", "StDir": "", "BldgType": "", "BldgName": "", "LevelType": "", "LevelName": "", "UnitType": "", "UnitName": "", "SubAddr": "", "StAddr": "", "Block": "", "Sector": "", "Nbrhd": "", "District": "", "City": "Burlington", "MetroArea": "", "Subregion": "Chittenden County", "Region": "Vermont", "RegionAbbr": "VT", "Territory": "", "Zone": "", "Postal": "", "PostalExt": "", "Country": "USA", "CntryName": "United States", "LangCode": "ENG", "Distance": 0, "X": -73.21207, "Y": 44.47588, "DisplayX": -73.21207, "DisplayY": 44.47588, "Xmin": -73.26207, "Xmax": -73.16207, "Ymin": 44.42588, "Ymax": 44.52588, "ExInfo": "", "OBJECTID": 2}},
{"geometry": {"x": -73.23148, "y": 44.48762, "spatialReference": {"wkid": 4326, "latestWkid": 4326}}, "attributes": {"Loc_name": "World", "Status": "T", "Score": 100, "Match_addr": "Burlington, Vermont", "LongLabel": "Burlington, VT, USA", "ShortLabel": "Burlington", "Addr_type": "Locality", "Type": "City", "PlaceName": "Burlington", "Place_addr": "City of Burlington, Vermont", "Phone": "", "URL": "", "Rank": 21, "AddBldg": "", "AddNum": "", "AddNumFrom": "", "AddNumTo": "", "AddRange": "", "Side": "", "StPreDir": "", "StPreType": "", "StName": "", "StType": "", "StDir": "", "BldgType": "", "BldgName": "", "LevelType": "", "LevelName": "", "UnitType": "", "UnitName": "", "SubAddr": "", "StAddr": "", "Block": "", "Sector": "", "Nbrhd": "", "District": "", "City": "City of Burlington", "MetroArea": "", "Subregion": "Chittenden County", "Region": "Vermont", "RegionAbbr": "VT", "Territory": "", "Zone": "", "Postal": "", "PostalExt": "", "Country": "USA", "CntryName": "United States", "LangCode": "ENG", "Distance": 0, "X": -73.23148, "Y": 44.48762, "DisplayX": -73.23148, "DisplayY": 44.48762, "Xmin": -73.28148, "Xmax": -73.18148, "Ymin": 44.43762, "Ymax": 44.53762, "ExInfo": "", "OBJECTID": 3}}]
0) results.features.pop(
{"geometry": {"x": -73.2109954, "y": 44.4759918, "spatialReference": {"wkid": 4326, "latestWkid": 4326}}, "attributes": {"Loc_name": "World", "Status": "T", "Score": 100, "Match_addr": "Burlington, Vermont", "LongLabel": "Burlington, VT, USA", "ShortLabel": "Burlington", "Addr_type": "Locality", "Type": "City", "PlaceName": "Burlington", "Place_addr": "Burlington, Vermont", "Phone": "", "URL": "", "Rank": 8.69, "AddBldg": "", "AddNum": "", "AddNumFrom": "", "AddNumTo": "", "AddRange": "", "Side": "", "StPreDir": "", "StPreType": "", "StName": "", "StType": "", "StDir": "", "BldgType": "", "BldgName": "", "LevelType": "", "LevelName": "", "UnitType": "", "UnitName": "", "SubAddr": "", "StAddr": "", "Block": "", "Sector": "", "Nbrhd": "", "District": "", "City": "Burlington", "MetroArea": "", "Subregion": "Chittenden County", "Region": "Vermont", "RegionAbbr": "VT", "Territory": "", "Zone": "", "Postal": "", "PostalExt": "", "Country": "USA", "CntryName": "United States", "LangCode": "ENG", "Distance": 0, "X": -73.2109954, "Y": 44.4759918, "DisplayX": -73.2109954, "DisplayY": 44.4759918, "Xmin": -73.2599954, "Xmax": -73.1619954, "Ymin": 44.4269918, "Ymax": 44.5249918, "ExInfo": "", "OBJECTID": 1}}
0) results.features.pop(
{"geometry": {"x": -73.21207, "y": 44.47588, "spatialReference": {"wkid": 4326, "latestWkid": 4326}}, "attributes": {"Loc_name": "World", "Status": "T", "Score": 100, "Match_addr": "Burlington, Vermont", "LongLabel": "Burlington, VT, USA", "ShortLabel": "Burlington", "Addr_type": "Locality", "Type": "City", "PlaceName": "Burlington", "Place_addr": "Burlington, Vermont", "Phone": "", "URL": "", "Rank": 13.72, "AddBldg": "", "AddNum": "", "AddNumFrom": "", "AddNumTo": "", "AddRange": "", "Side": "", "StPreDir": "", "StPreType": "", "StName": "", "StType": "", "StDir": "", "BldgType": "", "BldgName": "", "LevelType": "", "LevelName": "", "UnitType": "", "UnitName": "", "SubAddr": "", "StAddr": "", "Block": "", "Sector": "", "Nbrhd": "", "District": "", "City": "Burlington", "MetroArea": "", "Subregion": "Chittenden County", "Region": "Vermont", "RegionAbbr": "VT", "Territory": "", "Zone": "", "Postal": "", "PostalExt": "", "Country": "USA", "CntryName": "United States", "LangCode": "ENG", "Distance": 0, "X": -73.21207, "Y": 44.47588, "DisplayX": -73.21207, "DisplayY": 44.47588, "Xmin": -73.26207, "Xmax": -73.16207, "Ymin": 44.42588, "Ymax": 44.52588, "ExInfo": "", "OBJECTID": 2}}
m.draw(results)
Create Drive Time Area
import arcgis.network as network
= gis.properties.helperServices.serviceArea.url service_area_url
service_area_url
'https://route.arcgis.com/arcgis/rest/services/World/ServiceAreas/NAServer/ServiceArea_World'
= network.ServiceAreaLayer(service_area_url, gis=gis) sa_layer
= sa_layer.solve_service_area(results, default_breaks=[180],
result ='esriNATravelDirectionFromFacility') travel_direction
from arcgis.features import Feature, FeatureSet
= []
poly_feat_list for polygon_dict in result['saPolygons']['features']:
= Feature(polygon_dict['geometry'], polygon_dict['attributes'])
f1 poly_feat_list.append(f1)
= FeatureSet(poly_feat_list,
service_area_fset =result['saPolygons']['geometryType'],
geometry_type= result['saPolygons']['spatialReference']) spatial_reference
m.draw(service_area_fset)