|
POST
|
I've created a 3D polyline from a 3D point feature class and then reshaped the polyline feature class to follow the meandering of the river thawleg (centreline). I would like to calculate the Z values for the new vertices that are added to the 3D polyline based on the existing vertices that already have Z values and the distance along the polyline as a linear proportion of the elevation drop. Is there a way that I can achieve the following in python. Points (Red) were used to create the 3D polyline New vertices added through reshaping 3D Polyline
... View more
08-11-2016
08:10 AM
|
0
|
3
|
3155
|
|
POST
|
Hi Dan Solved it, it seems that the conversion from ECW to TiFF either when resampling or mosaicing the tiles to a new raster only works with Python 32 bit and not Python 64 bit. It runs perfectly under my Python 32 bit. I'd like to find out from ESRI what is the difference when running some of their tools under Python 32 bit vs Python 64 bit and why would it fail under Python 64 bit.
... View more
08-05-2016
06:39 AM
|
0
|
0
|
2996
|
|
POST
|
Hi Dan I'm working with eclipse IDE, but as mentioned if the image is TiFF it runs perfectly, it only fails with ECW images, yet it runs from ArcMap and ArcCatalog perfectly. I looked at the following link and still receive the same error message.
... View more
08-05-2016
06:12 AM
|
0
|
0
|
2996
|
|
POST
|
Just a note: I'm using ArcGIS 10.3.1 and Python 2.7.8
... View more
08-05-2016
05:30 AM
|
0
|
3
|
2996
|
|
POST
|
I've writen a Python script that resamples ECW images and at the same time converts the tiles to TiFF images. When I try to run the following script I receive the following error message: Processing COCT_W34A_23_8cm_2015 raster
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'GpMetadataFunctions, Version=10.3.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86' or one of its dependencies. The system cannot find the file specified.
File name: 'GpMetadataFunctions, Version=10.3.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86'
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at GetManagedType(Char* _assembly, Char* _path, Char* _className)
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. Error Message '''
Created on 05 Aug 2016
Resample and Convert
ECW images to TiFF
@author: PeterW
'''
# import site packages and modules
import arcpy
from pathlib import Path
# set arguments
index_layer = r"E:\Projects\2016\G112502\lyr\SubcatchA.lyr"
output_folder = r"E:\Projects\2016\G112502\CoCT_Imagery\SubCatchA\Tiles"
# set environment variables
arcpy.env.overwriteOutput = True
# create single image from tiles based on index selection
def tiles_to_mosaic(index_layer, output_folder):
with arcpy.da.SearchCursor(index_layer, ["RasterPath"]) as scur: # @UndefinedVariable
for row in scur:
raster_name = Path(row[0]).stem
arcpy.AddMessage("Processing {0} raster".format(raster_name))
out_raster = "{0}\\{1}.tif".format(output_folder, raster_name)
arcpy.Resample_management(row[0], out_raster, cell_size = 0.32, resampling_type = "NEAREST")
tiles_to_mosaic(index_layer, output_folder) Python Script I've even go so far as to set the input arguments to a single ECW image and the output to the output TiFF image, yet I still receive the same error message. I'm able to run the Resample Tool from ArcMap or ArcCatalog with no error messages. I've tested the following on TiFF images and the script runs successfully. Any advice in how to resolve the following will be appreciated.
... View more
08-05-2016
05:28 AM
|
0
|
4
|
5490
|
|
POST
|
Hi Dan Thanks for getting back to me. The reason for using the enumerator was to be able to update a specific list of fields within the UpdateCursor using the same formula without having to specify each index position (i.e. row[1], row[2]) etc. I solved the following by using the optional argument to specify the starting index number. The original post is under the following discusssion: Data Access Module: Update Cursor (Not Updating Records)
... View more
07-13-2016
12:29 PM
|
0
|
0
|
1818
|
|
POST
|
Hi Darren I was busy posting my answer to my own question, when your reply came through. By specifying the starting number of the index I was able to solve it. Thanks for your reply.
... View more
07-13-2016
12:22 PM
|
0
|
2
|
1818
|
|
POST
|
Hi All I solved it, I was correct that the index slice should be row[1:-1] what I had missed that the index starts at 0 and can be managed with an optional argument within Python Enumerate Function. # calculate percentage of landuse per watershed
def landuse_percentage(watershed, output_pivot):
watershed_fields = ["HydroID", "Shape_Area"]
valuedict = {r[0]: (r[1:]) for r in arcpy.da.SearchCursor(watershed, watershed_fields)} # @UndefinedVariable
arcpy.AddField_management(output_pivot, "CatchAreaKm2", "DOUBLE")
landuse_fields = [f.name for f in arcpy.ListFields(output_pivot)[1:]]
with arcpy.da.UpdateCursor(output_pivot, landuse_fields) as upcur: # @UndefinedVariable
for row in upcur:
keyvalue = row[0]
if keyvalue in valuedict:
arcpy.AddMessage("Processing Watershed {0}".format(keyvalue))
row[-1] = valuedict[keyvalue][0]/1000000
for i, landuse in enumerate(row[1:-1], 1):
row = (landuse*(28*28))/(valuedict[keyvalue][0])*100
print("Index: {0}, Landuse: {1}, CatchAreaKm2: {2}, Percentage: {3}".format(i, landuse, row[-1], row))
upcur.updateRow(row)
landuse_percentage(watershed, output_pivot) Thanks for all the help, from everyone.
... View more
07-13-2016
12:19 PM
|
0
|
0
|
1818
|
|
POST
|
Hi Dan Dan Patterson \ Luke Luke Pinner Just wonder if either of you have any idea why my enumerate function isn't working as expected. The index slice should be row[1:-1] yet it doesn't work, only row[1:] works, which shouldn't as it would include the newly added "CatchAreaKm2" field.
... View more
07-13-2016
11:56 AM
|
0
|
3
|
1818
|
|
POST
|
Hi Neil The field is added and identified within the list, yet when I step into line 15 I should have to adjust the index slice row[1:] to row[1:-1] to exclude the added field from fields being updated.
... View more
07-13-2016
08:41 AM
|
0
|
4
|
1818
|
|
POST
|
I've added a new field "CatchAreaKm2" (Double) to a File Geodatabase Table. I then create a list of fields of the table that will be used in an UpdateCursor. The problem that I have is that the newly added field is listed within the list of fields yet when I iterate through a sliced version of the fields (landuse) it doesn't recognize the newly added "CatchAreaKm2" field and I can't understand for the life of me why not. In order the get a list of the Landuse fields the index slice should be row[1:-1] yet if I use the following it skips the last landuse field ignoring the newly added field. in order to get the following to work I need to using the index slice row[1:] Any help solving why the newly field is not being recognized will be appreciated. [u'HydroID', u'Commercial_Forestry', u'Cultivated', u'Indigenous', u'Mines', u'Natural_Vegetation_Forest', u'Urban', u'Waterbodies', u'Wetlands', u'CatchAreaKm2'] Python: landuse_fields # calculate percentage of landuse per watershed
def landuse_percentage(watershed, output_pivot):
watershed_fields = ["HydroID", "Shape_Area"]
valuedict = {r[0]: (r[1:]) for r in arcpy.da.SearchCursor(watershed, watershed_fields)} # @UndefinedVariable
arcpy.AddField_management(output_pivot, "CatchAreaKm2", "DOUBLE")
landuse_fields = [f.name for f in arcpy.ListFields(output_pivot)[1:]]
print(landuse_fields)
with arcpy.da.UpdateCursor(output_pivot, landuse_fields) as upcur: # @UndefinedVariable
for row in upcur:
keyvalue = row[0]
if keyvalue in valuedict:
arcpy.AddMessage("Processing Watershed {0}".format(keyvalue))
# add catchment area km² to newly added field
row[-1] = valuedict[keyvalue][0]/1000000
for i, landuse in enumerate(row[1:]): # index slice not picking up newly added field
row = (row*(28*28))/(valuedict[keyvalue][0])*100
upcur.updateRow(row)
landuse_percentage(watershed, output_pivot) Python: Code (Currently working) # calculate percentage of landuse per watershed
def landuse_percentage(watershed, output_pivot):
watershed_fields = ["HydroID", "Shape_Area"]
valuedict = {r[0]: (r[1:]) for r in arcpy.da.SearchCursor(watershed, watershed_fields)} # @UndefinedVariable
arcpy.AddField_management(output_pivot, "CatchAreaKm2", "DOUBLE")
landuse_fields = [f.name for f in arcpy.ListFields(output_pivot)[1:]]
print(landuse_fields)
with arcpy.da.UpdateCursor(output_pivot, landuse_fields) as upcur: # @UndefinedVariable
for row in upcur:
keyvalue = row[0]
if keyvalue in valuedict:
arcpy.AddMessage("Processing Watershed {0}".format(keyvalue))
# add catchment area km² to newly added field
row[-1] = valuedict[keyvalue][0]/1000000
for i, landuse in enumerate(row[1:-1]): # index slice should be
row = (row*(28*28))/(valuedict[keyvalue][0])*100
upcur.updateRow(row)
landuse_percentage(watershed, output_pivot) Python: Code (Not working)
... View more
07-13-2016
08:18 AM
|
0
|
10
|
3926
|
|
POST
|
Hi Luke Thanks so much, now I understand where I was going wrong, much appreciated.
... View more
07-13-2016
05:48 AM
|
0
|
0
|
2248
|
|
POST
|
Hi Xander Thanks for the following, you are correct that I generally also don't update the original field values based on the calculations, due to bugs or errors. The landuse table that I have used is a output from Zonal Histogram that represents the number of cells for each landuse within each watershed. The following is generated within a separate function just before the following, so the risk of the values being overwritten is managed.
... View more
07-13-2016
05:28 AM
|
1
|
0
|
2248
|
|
POST
|
Hi Luke The following worked perfectly, thanks . Would you mind helping me understand why my original for loop didn't work as the printed results within the console were correct?
... View more
07-13-2016
05:19 AM
|
0
|
2
|
2248
|
| Title | Kudos | Posted |
|---|---|---|
| 3 | 01-16-2012 02:34 AM | |
| 1 | 05-07-2016 03:04 AM | |
| 1 | 04-10-2016 01:09 AM | |
| 1 | 03-13-2017 12:27 PM | |
| 1 | 02-17-2016 02:34 PM |
| Online Status |
Offline
|
| Date Last Visited |
03-04-2021
12:50 PM
|