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
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 | |
import numpy | |
input = r"C:\Work\Waypoints.shp" | |
arr = arcpy.da.FeatureClassToNumPyArray(input, ('ident', 'Latitude', 'Longitude')) | |
for row in arr: | |
ident = row["ident"] | |
lat = row["Latitude"] | |
lon = row["Longitude"] | |
sql = "INSERT INTO MyTable(WaypointName,Lat,Lon) VALUES('" + str(ident) + "'," + str(lat) + "," + str(lon) + ");" | |
print sql |
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
' this button allows the user to switch between read only and editing | |
Private Sub ToggleReadOnlyButton_Click() | |
SetFormEditability | |
End Sub | |
' you can only toggle the form's allowedits property is it is clean so if the | |
' form is dirty then ask if it's ok to flush changes | |
Private Sub SetFormEditability() | |
If Me.Dirty = True Then | |
If MsgBox("Save changes?", vbYesNo, "Confirm") = vbYes Then |
OlderNewer