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
Dim MyString As String = "Fish, Cat, Dog" | |
Dim MyList() As String = MyString.Split(",") | |
For Each Item As String In MyList | |
MsgBox(Item) | |
Next |
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
# basic example of opening a shapefile and then looping through the records and outputting them to console | |
import arcpy | |
# Supply a path to the shapefile | |
fc = "C:/Temp/MurphyProjected.shp" | |
# we'll need to create a searchcursor a little further on to access the records in the layer. the cursor has a fields parameter | |
# we could just submit a * to gather all columns except that we need the Shape column returned as a token, e.g. Shape@, | |
# so we have to submit all the columns as a list with Shape changed to the Shape@ token that will allow us to get at geometry info. | |
# The easiest way to do this is to loop through the column names and load them into a list making our edits as needed |
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
import arcpy | |
fc = "C:/Work/VitalSigns/ARCN-CAKN Dall Sheep/Data/LegacySurveyUnits/ARCN_Subunits_Sheep_WGS84.shp" | |
fieldsList = arcpy.ListFields(fc) #get the fields | |
fields = [] # create an empty list | |
# loop through the fields and add the columns to the list, change the Shape column (containing geometry) into a token, | |
for field in fieldsList: | |
if field.name == "Shape": | |
fields.append("Shape@") | |
else: | |
fields.append(field.name) |
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
-- SQL Server 2008R2, there are better functions in later versions of Sql Server such as STContains() | |
SELECT Animals.GroupNumber | |
FROM LegacyUnits INNER JOIN | |
Animals ON LegacyUnits.PolygonFeature.STIntersects(Animals.Location) = 1 | |
-- Here is an UPDATE query example: | |
UPDATE Animals | |
SET Unit = LegacyUnits.LegacyUnitID | |
FROM LegacyUnits INNER JOIN | |
Animals ON LegacyUnits.PolygonFeature.STIntersects(Animals.Location) = 1 |
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
Private Function OpenFile() As String | |
'build and configure an OpenFileDialog | |
Dim OFD As New OpenFileDialog | |
With OFD | |
.AddExtension = True | |
.CheckFileExists = True | |
.Filter = "Excel files(.xlsx)|*.xlsx|Excel files (*.xls)|*.xls" | |
.Multiselect = False | |
.Title = "Select an workbook to open" | |
End With |
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
use ARCN_Sheep | |
SELECT Survey, LegacyUnitID, Category, n | |
FROM [CompositionCountsByUnit]UNPIVOT (n FOR Category IN (Ewes, EweLike, Lambs, Rams_LessThanFullCurl, Rams_FullCurl, UnclassifiedRams, UnclassifiedSheep, | |
Yearlings, Rams1_2Curl, Rams3_4Curl, Rams7_8Curl, Rams1_4Curl, Rams_GT_7_8Curl)) u; |
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
import pyodbc | |
connection = pyodbc.connect('DRIVER={SQL Server};SERVER=MYSQLSERVER\SERVERNAME;DATABASE=MyDatabase') | |
cursor = connection.cursor() | |
# select query example | |
cursor.execute("SELECT * FROM MyTable") | |
row = cursor.fetchone() | |
if row: | |
print row |
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
connection = pyodbc.connect('DRIVER={SQL Server};SERVER=' + server + ';DATABASE=' + database, autocommit = False) | |
cursor = connection.cursor() | |
try: | |
cursor.execute("INSERT INTO MyTable(a,b) VALUES('a','b')") | |
except Exception as ex: | |
print 'Error: ' + str(ex) |
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
for n in range(1,20010): | |
if not n % 10000: | |
filename = "ImportGPSPointsLog_" + str(n/10000) + ".sql" | |
print str(n) + ' ' + filename |
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
import arcpy | |
# Note: Sometimes Shape@ is SHAPE@ which can mess things up | |
# one way | |
InFile = r'c:\temp\z144726127333.shp' | |
with arcpy.da.SearchCursor(InFile,'SHAPE@') as Cursor: | |
for row in Cursor: | |
print row[0].WKT | |
# another way because sometimes the first way doesn't work. This version will select two columns. |
OlderNewer