POST
|
I'm trying to set an arcpy da insert cursor to iterate through a dictionary that adds in the rhino's name. I'm missing a code that would loop through the cursor. def rhinoTracker(Rhino, X, Y, dictionary):
# Sets the variable for arcpy.Point
vertex = arcpy.Point(X, Y)
# If the Rhino is in the dictionary, points are added.
if Rhino in dictionary:
vertexArray = dictionary[Rhino]
vertexArray.add(vertex)
#print str(dictionary.values())
# If the Rhino is not in the dictionary, an array created.
else:
vertexArray = arcpy.CreateObject("Array")
vertexArray.add(vertex)
dictionary[Rhino] = vertexArray
#print str(dictionary.values())
#for Rhino in dictionary:
print "This the key {0}".format(Rhino)
print "These are {0}'s points {1}".format(Rhino, dictionary[Rhino])
print "{0} has {1} points".format(Rhino, str(len(dictionary[Rhino])))
#--------------------------------------------------------------------------
# Imports the csv and arcpy modules.
import csv
import arcpy
# Sets up the workspace environment and overwrite output.
arcpy.env.workspace = "E:\College\Penn State\GEOG 485\Lesson 4\JHorwitz_Lesson4_Submission\Shapefiles"
arcpy.env.overwriteOutput = True
#--------------------------------------------------------------------------
# Sets a path for the folder containing the shapefile.
Path = "E:\College\Penn State\GEOG 485\Lesson 4\JHorwitz_Lesson4_Submission\Shapefiles"
# Uses the "MysteryState.shp" as the spatial reference.
spatialpath = "E:\College\Penn State\GEOG 485\Lesson 4\JHorwitz_Lesson4_Submission\Shapefiles\MysteryState.shp"
# Sets up the "RhinoObservations.csv" as the csv file.
RhinoObservation = open("E:\College\Penn State\GEOG 485\Lesson 4\JHorwitz_Lesson4_Submission\RhinoObservations.csv", "r")
# Creates the Polyline shapefile as "RhinoTrack.shp" using "MysteryState.shp" as the spatial reference and the folder to store the shapefile.
arcpy.CreateFeatureclass_management(Path, "RhinoTrack.shp", "POLYLINE", "", "DISABLED", "DISABLED", spatialpath)
# Creates a new text field for the Rhino polyline.
arcpy.AddField_management("RhinoTrack.shp", "Name", "TEXT")
# Sets up the file path to "RhinoTrack.shp"
rhinoLine = "E:\College\Penn State\GEOG 485\Lesson 4\JHorwitz_Lesson4_Submission\Shapefiles\RhinoTrack.shp"
# Sets up the spatial reference for the rhinoLine.
spatialRef = arcpy.Describe(rhinoLine).spatialReference
#--------------------------------------------------------------------------
# Sets up a csv reader and will process the header.
csvReader = csv.reader(RhinoObservation, delimiter=",")
header = csvReader.next()
xIndex = header.index("X")
yIndex = header.index("Y")
rhinoIndex = header.index("Rhino")
# Creates the rhinoList dictionary.
rhinoList = {}
# Loop through the lines in the csv file to get the coordinates and rhino name.
for row in csvReader:
Rhino = row[rhinoIndex]
X = row[xIndex]
Y = row[yIndex]
rhinoTracker(Rhino, X, Y, rhinoList)
with arcpy.da.InsertCursor(rhinoLine, ("SHAPE@")) as cursor:
for Rhino in cursor:
polyline = arcpy.Polyline(vertexArray, spatialpath)
cursor.insertRow((polyline,))
# Updates and fills up the new text field as OpenStreetMap using a "with" loop.
with arcpy.da.UpdateCursor("RhinoTrack.shp", "Name") as cursor:
#Uses a "for" loop to insert each row.
for Name in cursor:
Name[0] = Rhino
cursor.updateRow(Name)
Between line 79-82, I need to use the insert cursor to iterate through a dictionary and I'm not sure how.
... View more
10-06-2018
07:32 AM
|
0
|
3
|
3070
|
POST
|
With the definition at least, would there need to be a variable that needs to changed around so I could have the results change to "Rhino : {(Point 1),(Point 2)}" instead of {Rhino : [(Point 1),(Point 2)]}? That been my biggest problem so far.
... View more
10-03-2018
09:50 PM
|
0
|
1
|
639
|
POST
|
This the csv file it is based off of and there a re a total of 51 points. https://www.e-education.psu.edu/geog485/sites/www.e-education.psu.edu.geog485/files/data/RhinoObservations.csv
... View more
10-03-2018
08:23 PM
|
0
|
3
|
639
|
POST
|
I'm currently new to python and working on a Class Project trying to create multiple polylines based on the tracking of Rhinos. I have the approach right, but I somehow have the variables switched around. The Rhino would be the key value, and the points would have to be added into it. The example would be "Rhino : {(Point 1),(Point 2)}". Somehow I can't get it. I can get the polyline to form, but I only get one giant line and not a multiple set of polylines based on the Rhino. Here is the script I have written down.(re-edited to just the definition of the function) def rhinoTracker(Rhino, X, Y, dictionary):
XYCoord = (X, Y)
if Rhino not in dictionary:
dictionary[Rhino]= []
dictionary[Rhino].append((XYCoord))
... View more
10-03-2018
07:10 PM
|
0
|
6
|
1089
|
POST
|
I was able to finally find the solution! I had to add an extra ".shp" to "_projected" as "_projected.shp." to fix the Error: 999999.
... View more
09-12-2018
01:01 PM
|
0
|
0
|
793
|
POST
|
(Edit: I shortened the script as a big portion of it wasn't part of the main problem.) I'm working on a script to re-project shapefiles from a selected shapefile with a different projection. While the execution of the tool works, it fails when overwriting the same file regardless of adding in arcpy.env.overwriteOutput = True. Here is the script used: if srcDesc.SpatialReference.Name == targetDesc.SpatialReference.Name:
continue
#Shapefiles in the targeted folder that don't match will reprojected to the selected shapefile.
else:
#Replaces the TargetFolder's ".shp" at the end of the end of the name with "_projected."
ReprojectedData = InFolder.replace(".shp", "_projected")
#Tool re-projects the datasets that doesn't match the spatial reference of the targeted shapefile.
arcpy.Project_management(InFolder, ReprojectedData, InFile)
#Displays a message of success of the projected datasets.print "Projected " + str(InFolder)
arcpy.AddMessage("Projected " + str(InFolder)) Is there a different way of using an overwrite output for a script such as this?
... View more
09-08-2018
09:28 AM
|
0
|
6
|
1087
|
POST
|
I'm a beginner to Python coding and now working on a basic script program, where I'm using both Print and arcpy.AddMessage/arcpy.AddError in a standalone script for ArcMap or in Pythonwin. However, I'm having issues with how I can do this for arcpy.GetMessages in PythonWin to find a traceback error. I tried using: msgs = arcpy.GetMessages(2) print (msgs) arcpy.AddMessage(msgs) But couldn't get any traceback message. Is there a code that helps show the traceback error in Pythonwin? Full Script below: import arcpy from arcpy import env from arcpy.sa import * arcpy.env.overwriteOutput = True try: # Sets the workspace evironment settings. env.workspace = "E:/College/Penn State/GEOG 485/Lesson 1/Lesson1" inRaster = "foxlake" contourInterval = 25 baseContour = 0 outContours = "E:/College/Penn State/GEOG 485/Lesson 1/Lesson1/ContourFoxLake.shp" arcpy.CheckOutExtension("Spatial") arcpy.sa.Contour(inRaster, outContours, contourInterval, baseContour) # Report a success message print "Contour creation successful!" arcpy.AddMessage("Contour creation successful!") except: # Report an error message print "Failed to create the contour." arcpy.AddError("Failed to create the contour.") # Report any error messages that the Contour tool might have generated msgs = arcpy.GetMessages(2) print (msgs) arcpy.AddMessage(msgs)
... View more
08-27-2018
06:02 PM
|
0
|
2
|
885
|
POST
|
I was able to get it working again somehow. I probably didn't set the address locator to Street Name as that was the Address Locator style. This locator would only be used as part of a demo web application for future projects.
... View more
02-04-2018
05:32 PM
|
0
|
1
|
508
|
POST
|
I've created an address locator for only just street names (no numbers and line shape). However, when using the geocoding tools in ArcGIS(5.1), the tools would that the address is not found. I typed the street name in the correct spelling, but is not showing up for some reason. Is there something I'm missing for an address locator with just only in street name form? Also: When I did this for single house locator(points) it works just fine.
... View more
02-04-2018
07:08 AM
|
0
|
3
|
1325
|
POST
|
I've downloaded the 10.5 program last month and haven't had any problems until now. I just tried starting up one of the programs (ArcMap, ArcCatalog etc.) and it just stays on the initialization screen. I've tried uninstalling and re-downloading the program, but I still get the same issue. I have a Windows 10 operating system that I've been using since last February with ArcGIS 10.4 and haven't had issues with that. If anyone can help me out that would be great.
... View more
06-05-2017
02:45 PM
|
0
|
3
|
4902
|
Online Status |
Offline
|
Date Last Visited |
4 weeks ago
|