This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Name: Python ArcPy Connect to SDE and versions | |
#Author: Bryan McIntosh | |
#Description: An approach to connect to SDE, create a new version, and change | |
# to the new version - inside a python script. | |
import arcpy, datetime, os, tempfile, shutil | |
#Create a string of the date to append to version name (to keep unique) | |
now = datetime.datetime.now() | |
strDate = str(now.year) + str(now.month) + str(now.day) + str(now.hour) + str(now.minute) + str(now.second) | |
#Create a temp directory using tempfile module to store SDE connection files | |
sdeTempPath = tempfile.mkdtemp() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Name: Multiple Field Key to Single Field Key for Relates using Python and ArcPy | |
#Author: Bryan McIntosh | |
#Description: For updating a single LINK_ID field in both the parent and child table | |
# based on a natural 4 column composite index relationship. | |
import arcpy | |
## VARIABLES ## | |
edit_ws = r'C:\SpatialTimes.gdb' #Edit workspace | |
xs_fc = r'C:\SpatialTimes.gdb\CrossSection' #parent FC | |
xs_tbl = r'C:\SpatialTimes.gdb\CrossSection_RatingCurves' #related table | |
xs_att = ['Link_ID','F1','F2','F3','F4','OID@'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Name: ArcMap Layers to LYR Files with Python | |
#Author: Bryan McIntosh | |
#Description: Iterate through an ArcMap MXD, and export all layers to LYR files. | |
import arcpy, os | |
#Set the working directory to where the Python file is stored | |
cwd = os.getcwd() | |
#Set the location of the MXD file | |
mxdPath = os.path.join(cwd,"MyMap.mxd") | |
#Set the location to store LYR files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Name: Generate a token from ArcGIS Server using python | |
#Author: Bryan McIntosh | |
#Description: Python script to generate a token from ArcGIS Server for use with secure map services. | |
# This sample uses the 'requests' module (https://pypi.python.org/pypi/requests/2.7.0) | |
import requests | |
params = {'username': 'USERNAME', 'password': 'PASSWORD', 'client': 'requestip', 'f': 'json'} | |
request = requests.post('https://YOUR.SITE.com/arcgis/tokens',params=params) | |
response = request.json() | |
myToken = response["token"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Name: Export ArcGIS Server Map Service Layer to Shapefile with Iterate | |
#Author: Bryan McIntosh | |
#Description: Python script that connects to an ArcGIS Server Map Service and downloads a single vector layer | |
# to shapefiles. If there are more features than AGS max allowed, it will iterate to extract all features. | |
import urllib2,json,os,arcpy,itertools | |
ws = os.getcwd() + os.sep | |
#Set connection to ArcGIS Server, map service, layer ID, and server max requests (1000 is AGS default if not known). | |
serviceURL = "https://domain/arcgis/rest/services" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Name: Export ArcGIS Server Map Service Layer to Shapefile | |
#Author: Bryan McIntosh | |
import urllib2, os, arcpy | |
# Variables | |
myUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services" | |
myService = "/Census/MapServer" | |
myParams = "/3/query?where=1%3D1&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=*&returnGeometry=true&geometryPrecision=&outSR=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&returnZ=false&returnM=false&returnDistinctValues=false&returnTrueCurves=false&f=pjson" | |
# Query ArcGIS Server Map Service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Name: SQL Server Procedure with STIntersection | |
-- Author: Bryan McIntosh | |
-- Description: Populated data table from SQL Server Spatial query | |
CREATE PROCEDURE [dbo].[prc_NoaaDataLoad] | |
@dt datetime, --DateTime from NOAA header info | |
@val float, --Value of weather data (mm of rain, temperature in F/C, etc) | |
@wType varchar(20), -- Type of data stored (precipitation, temperature, etc) | |
@wkt varchar(8000) --polygon shape (geography type) | |
AS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Name: SQL Server STIntersection Example | |
-- Author: Bryan McIntosh | |
/****** Part 1: Intersect Point and Polygon ******/ | |
DECLARE @thePolygon GEOGRAPHY, @pointIN GEOGRAPHY, @pointOUT GEOGRAPHY; | |
SET @thePolygon = GEOGRAPHY::STGeomFromText('POLYGON((-78.50932668617881 45.024933647425115, -78.53403351361905 44.9898648154388, -78.48446979547693 44.97239241709962, -78.45973073293072 45.007441690111115, -78.50932668617881 45.024933647425115))', 4269); | |
SET @pointIN = GEOGRAPHY::STGeomFromText('POINT(-78.51 45.00)', 4269); | |
SET @pointOUT = GEOGRAPHY::STGeomFromText('POINT(-65.00 35.00)', 4269); | |
SELECT @pointIN.STIntersection(@thePolygon).ToString(); | |
SELECT @pointOUT.STIntersection(@thePolygon).ToString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Name: BitCode/BitFlag Python Example | |
# Author: Bryan McIntosh | |
###################################################################### | |
# Set bitCode/Flag to run various/multiple sections of code. | |
# Add the numbers together for each section to run. | |
# 1: Call section 0 - example: Clean temp directory | |
# 2: Call section 1 - example: Run FTP Download | |
# 4: Call section 2 - example: Analyze FTP files and clean | |
# 8: Call section 3 - example: Say hi | |
###################################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires: Esri's ArcPy.da module and PyODBC module | |
#Note: Search for <VARIABLE> to replace with new values, and update inputs | |
import arcpy, pyodbc | |
def fn_ReadPolygons(fc_in,wkid): | |
#This function loops through a polygon layer and converts geometry to WKT format | |
#Additional attributes can also be added for insert | |
#The input layer and WKID of the Geography type is required | |
for row in arcpy.da.SearchCursor(fc_in, ["SHAPE@WKT"]): |