|
POST
|
This sounds like a great idea. NumPy arrays stored in my experience very efficiently, so if you have zero's/nodata etc you probably will be just fine memory wise. You'd have to convert your line to points and then convert the points to numpy row-col coordinates using basic geometric arithmetic against your extent and cell size. Thanks for your input, Curtis. So if I have converted my rasters to a list of numpy arrays and my polyline as a numpy row/col array too, what do you envision as the next step?
... View more
03-17-2014
04:55 AM
|
0
|
0
|
1357
|
|
POST
|
2. tested true (also tried a fake hyperlink which tested false) This is because the string literal is forced. The problem is that because you have stored your file paths/links with single "\" backslashes, Python is evaluating these as escape characters. If you were to replace: os.path.exists(r"F:\Lp04\PROV NORTHGLEN\DWG\SHEET 1.DWG") With: os.path.exists("F:\Lp04\PROV NORTHGLEN\DWG\SHEET 1.DWG") Then it will evaluate as false. Additionally, I tested these: These evaluate as True: os.path.exists("F:\\Lp04\\PROV NORTHGLEN\\DWG\\SHEET 1.DWG") os.path.exists("F:/Lp04/PROV NORTHGLEN/DWG/SHEET 1.DWG") I didn't find any way to apply a .replace method on the stored paths you have because it will always incorrectly evaluate the second backslash in each stored path and fail. You will have to correct the source data with some other means as far as I can tell. Although I'd really like to see a Python solution.
... View more
03-11-2014
05:04 AM
|
0
|
0
|
4512
|
|
POST
|
Well, I added a new field and recalculated it so all \ became \\. Still, every single hyperlink showed up on my text file when I ran the original code after doing that (and I did change the field name). So not sure where to go from here. Maybe another dumb idea but make sure you can see the F: drive from where you are executing the Python script. I stay away from mapped drives and opt for using UNC paths for everything file/directory related (which also has an issue with character limits). Sorry I cannot help any more on this one as I am not sure what else I could do.
... View more
03-10-2014
10:44 AM
|
0
|
0
|
4512
|
|
POST
|
Forgot to add, also tried James idea and still all showed up. Your issue is related to how Python is handling the escape characters ("\") in your path names. As Joshua corrected my post, you will not be able to overcome your problem by simply attempting to string.replace() method on the values, and I have not found any other way to deal with this. For now, you'd have to calculate a new field like Joshua suggested. Edit: I noticed you said you tried Joshua's suggestion but I think you may have missed the full solution as it worked for me. That is if I repalce my test string to this:
Roll = "H:\\exists\\broken\\dfBA D.csv"
It will get correctly evaluated in any test logic: if os.path.exists(Roll):
print "roll exists: " + Roll
else:
print "roll failed"
... View more
03-10-2014
10:19 AM
|
0
|
0
|
4512
|
|
POST
|
See if this works -- replace "\" with "\\" in your path string formation:
import arcpy
import os
fc = r" C:\Users\GIS\Documents\TEST 2-25\project_test.shp"
fields = ["PROJECT_DW"]
with arcpy.da.SearchCursor (fc,fields) as cursor:
for row in cursor:
Roll = str(row[0])
Roll = Roll.replace("\\", "\\\\")
if os.path.exists(Roll):
pass
else:
f = open(r"C:\Users\GIS\Documents\brokenlinks.txt","a")
f.write(Roll + os.linesep)
f.close()
This is also valid way to deal with it too: roll = roll.replace('\\', r'/')
... View more
03-10-2014
07:45 AM
|
0
|
0
|
4638
|
|
POST
|
Sure, here are examples of types of hyperlinks we will search through: folders: F:\LP04\COPP DUNN PLANTATION pdfs: F:\MSL\EMAIL SURVEYS\STANDARD PACIFIC\DUNN PLANTATION\L65 GBBF 10-30-03.PDF dwgs: F:\LP04\COPP DUNN PLANTATION\DWG\116-03-295 LT65.DWG If spaces are an issue, than I'm pretty much screwed. There is way too much data to change all the names.. Tried the print function- again displayed ALL the hyperlinks instead of just the broken ones (I entered some fake links for testing). I tested for spaces in the filename and the os.path.exists picked it up just fine. I am wondering if the path is not constructed well enough though. My best guess is that you are not able to apply string literal to the evaluation. For example, this would evaluate as "else":
roll = 'H:\exists\broken\dfBA D.csv'
if os.path.exists(roll):
print "roll exists: " + roll
else:
print "roll failed"
However, this would evaluate as "exists":
roll = r'H:\exists\broken\dfBA D.csv'
if os.path.exists(roll):
print "roll exists: " + roll
else:
print "roll failed"
The difference being that the "roll" variable is set with an "r" in front of the actual string.
... View more
03-10-2014
07:13 AM
|
0
|
0
|
4638
|
|
POST
|
James, Assuming 32bit values, you're still only looking at something like 268MB (236*552*540*4 bytes) of data, which should fit into memory without a problem. Doing that for both your rasters and points would be a good place to start as Curtis mentions, as your sampling has to iterate over all points and rasters which isn't particularly fast. Another option that would take more work is to stack the rasters using multidimensional arrays, such as with NumPy or NetCDF. Then, you can pull out the values of all 540 rasters by sampling a single vector (all rasters at one point) which should greatly improve performance. cheers, Shaun I'm all ears. Could you provide just a tad more guidance on this? What would the approach look like? 1. Loop all 540 and convert to a list of numpy arrays
rasterarray = []
arcount = 1
for conraster in concrasters:
rasArray = "rasArray" + str(arcount)
rasArray = arcpy.RasterToNumPyArray(conraster)
rasterarray.append(rasArray)
arcount = arcount + 1
2. Sample with my input polyine. I am not exactly sure of the options here. Suggestions? Thanks!
... View more
03-10-2014
05:27 AM
|
0
|
0
|
1357
|
|
POST
|
Can you post an example of how the hyperlink looks? Maybe it is a character evaluation thing that isn't working as expected. Also, just for kicks, print out "Roll" to verify it
import arcpy
import os
fc = r" C:\Users\GIS\Documents\TEST 2-25\project_test.shp"
fields = ["PROJECT_DW"]
with arcpy.da.SearchCursor (fc,fields) as cursor:
for row in cursor:
Roll = str(row[0])
## print out the link to verify it
#try to print it like this first:
print "{0}".format(row[0])
#try to print it like this too:
print str(Roll)
if os.path.exists(Roll):
pass
else:
f = open(r"C:\Users\GIS\Documents\brokenlinks.txt","a")
f.write(Roll + os.linesep)
f.close()
... View more
03-10-2014
05:13 AM
|
0
|
0
|
4638
|
|
POST
|
Hi, I adapted some code I found online to search for broken (moved or renamed) hyperlinks in a shapefile. It should write all broken links to a text file, but instead it is writing ALL the hyperlinks to the text file. Any advice on what to change? I know extremely little about python. Also, I have arcmap 10.1 thank you! import arcpy
import os
fc = r" C:\Users\GIS\Documents\TEST 2-25\project_test.shp"
fields = ["PROJECT_DW"]
with arcpy.da.SearchCursor (fc,fields) as cursor:
for row in cursor:
Roll = str(row[0])
if os.path.exists(Roll):
pass
else:
f = open(r"C:\Users\GIS\Documents\brokenlinks.txt","a")
f.write(Roll + os.linesep)
f.close() In other words, it is evaluating everything as "broken". This may seem like a silly question but is "PROJECT_DW" the correct field that contains the paths? Also: would the evaluation fail if there are blank spaces in your "Roll" string variable? Maybe you should attempt to deal with that possibility: Roll = str(row[0])
Roll = Roll.strip()
... View more
03-07-2014
11:14 AM
|
0
|
0
|
4638
|
|
POST
|
What is your data source? What is the offending python code that you think is the problem?
... View more
03-07-2014
03:13 AM
|
0
|
0
|
3417
|
|
POST
|
This raster is pretty small. If you are at 10.1 or later, have you considered copying it to the in_memory workspace and seeing if that runs faster (I would expect it too, though you may have to try the different sampling tools to see which one works best.) Hi Curt, I'd have to copy the whole set of 540 rasters into in_memory. Not adverse to that, and I will give it a go!
... View more
03-04-2014
08:02 AM
|
0
|
0
|
1357
|
|
POST
|
I am terrible with the field calculator myself, but shouldn't it be (emphasis in bold): def Reclass(route_ty_1):
if route_ty_1 == 'Bus':
return 338
elif route_ty_1 == 'LIGHT RAIL':
return 281
elif route_ty_1 == 'METRO':
return 335
elif route_ty_1 == 'Rail':
return 282
elif route_ty_1 == 'Commuter Bus':
return 336 Also, maybe have an 'else' in the statement as well to pickup anything that doesn't evaluate in your if statement. edit: upvoted Joshua's solution v: a more complete answer. Mine was lazy 🙂
... View more
03-04-2014
05:29 AM
|
0
|
0
|
2664
|
|
POST
|
I don't think this is possible with arcpy. You would have to implement a 3rd party library like cx_Oracle to do this. We use this library but are simply building the SQL and invoking it runtime, so I don't have specific examples for PL/SQL packages or procedures. But there is plenty of info and examples out there: http://stackoverflow.com/questions/18267935/return-variable-from-cx-oracle-pl-sql-call-in-python
... View more
03-04-2014
02:34 AM
|
0
|
0
|
2772
|
|
POST
|
Well, I started a test run with the ExtractMultiValuesToPoints method --- going on 5hrs now and my trigger finger is itching to kill the process as it is worse than sa.Sample at this point. Any input is appreciated! j
... View more
03-03-2014
08:26 AM
|
0
|
0
|
1357
|
|
POST
|
I am invoking arcpy.sa.Sample() method on 540 individual rasters in a FGDB using a point feature class in the same workspace that contains 50 points. S-L-O-W is the word. Alternatives that have better performance? (prelim testing with ExtractMultiValuesToPoints doesn't offer any better performance). The 540 rasters I am processing: 236 cols 552 rows 2400, 2400 cellsize The Point FC has 50 points. It take about 3 hours to generate an output result and I need to drastically reduce this. Non-ESRI solutions are acceptable! Thanks, James
... View more
03-03-2014
05:53 AM
|
0
|
7
|
1750
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-17-2020 10:47 AM | |
| 1 | 10-25-2022 11:46 AM | |
| 1 | 08-08-2022 01:40 PM | |
| 1 | 02-15-2019 08:21 AM | |
| 2 | 08-14-2023 07:14 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-22-2025
02:28 PM
|