POST
|
Thanks Brian. Does not seem to work unfortunately as the values don't change. Please see the code. import arcpy
import os
import string
import sys
import fileinput
from arcpy import env
arcpy.env.overwriteOutput=True
from arcpy.sa import*
env.workspace = r"H:\PROGRAMMES\10_OTHER_PROJECTS\26_04072022_KEV"
OUT_workspace = r"H:\PROGRAMMES\10_OTHER_PROJECTS\26_04072022_KEV_NEW"
Lyrx = "AE000S570_005M5001P01M041.lyrx"
# Copy new file into new folder
arcpy.Copy_management(Lyrx, OUT_workspace + "\\" + "AE000S570_005M5001P01M041.lyrx")
arcpy.Copy_management(Lyrx, OUT_workspace + "\\" + "AE000S560_005M5001P01M041.lyrx")
with open(OUT_workspace + "\\" + "AE000S560_005M5001P01M041.lyrx") as fp:
lyrx = fp.read()
lyrx.replace('570,\n"max"', '560,\n"max"')
... View more
07-06-2022
03:42 AM
|
0
|
1
|
1360
|
POST
|
Thanks again @RPGIS. I'm not very familiar with the activeSlice dictionary concept unfortunately. Must admit I'm a bit lost now. Please let me pass you the .lyrx file see if that makes things easier. I just need to replace the rangeDimensionValue of several files. For example, from 570 to 560. I was initially using line.replace but that would change the "customFullExtent" part as well and I need that to keep the same values.
... View more
07-05-2022
07:36 AM
|
0
|
1
|
1398
|
POST
|
Thanks very much @RPGIS, I appreciate. Yes, I'm using Python. I've tried this: maxvalue = {"max": 570}
for i, line in enumerate(fileinput.input(OUT_workspace + "\\" + "AE000S560_005M5001P01M041.lyrx", inplace=1)):
#insert line exception below for specific line to update
if i ==(706):
maxvalue["max"] = "560"
sys.stdout.write(maxvalue["max"]) But the result I'm getting is simply "560". All the rest of the contents in the .lyrx file are gone. Any suggestions?
... View more
07-05-2022
05:24 AM
|
0
|
3
|
1425
|
POST
|
Hi, I'm trying to replace some characters within a lyrx file. In this example I need to replace "570" with "560" The problem I have is that two lines are identical but I only need to replace one (highlighted in yellow in the image below) and not the one a few lines above the highlighted one. The code I'm using: for i, line in enumerate(fileinput.input(OUT_workspace + "\\" + "AE000S560_005M5001P01M041.lyrx", inplace=1)):
sys.stdout.write(line.replace('"max" : 570', '"max" : 560')) I would really appreciate any help. I'm not sure how to target a specific line within the file. Many thanks.
... View more
07-05-2022
04:01 AM
|
0
|
10
|
1575
|
POST
|
Hi, I got a sample script from an older post but I cannot get it working. I'm trying to remove duplicate values within records in a FC. For example, in the first row above, I need to get rid of one "63350" and one "70169" keeping the ";" as delimiters. import arcpy
InputFC = r"H:\PROGRAMMES\10_OTHER_PROJECTS\24_ATTRIBUTION_CHECKS\From_RTJ.gdb\REFID_sample_1_1"
InputField = "REF_ID"
cursor = arcpy.da.UpdateCursor(InputFC, ["REF_ID"])
for row in cursor:
strList = row.Value(InputField).split("; ")
strSet = set(strList)
str = "; "
conStr = str.join(strSet)
row.setValue(InputField, conStr)
cur.updateRow(row)
del row
del cursor I'm getting an error related to line 12: AttributeError: 'list' object has no attribute 'Value' Any help would be greatly appreciated. Thanks
... View more
05-15-2019
08:31 AM
|
0
|
6
|
1019
|
POST
|
That works perfect Dan. All the slightly different approaches above give same result. Really appreciate your help once again.
... View more
11-28-2018
01:20 AM
|
0
|
0
|
657
|
POST
|
Thank you Xander. It seems there is a minor issue in line 19. I also tried with float(len(max_values) but getting the same error. Other than that, I'm sure is perfect. Very nice the way it prints the max values for each raster. Both Jake's and Dan's are working and giving the same result. Many thanks.
... View more
11-28-2018
01:16 AM
|
0
|
0
|
657
|
POST
|
I see. At first run I got an error in line 13 below. As the rasters are floating point I removed 'int' from the line (as below). env.workspace = r"D:\000_TEST_MAGNITUDE_summary\MAX_VAL_calculation\Vel_rasters.gdb"
# Create list
maxVals = []
# Iterate through each raster and append max val to list
for raster in arcpy.ListRasters("*"):
val = arcpy.GetRasterProperties_management(raster, "MAXIMUM")
maxVal = val.getOutput(0)
maxVals.append(maxVal)
# Sum list
sum = 0
for val in maxVals:
sum = sum + val
# Find Mean
meanVal = sum / len(maxVals)
print(meanVal) But now I'm getting this error which I guess it may be related.
... View more
11-27-2018
09:10 AM
|
0
|
2
|
2525
|
POST
|
Thank you Jake. That looks promising. Just trying now but I got an error in line 16. Is it '+' or '='?
... View more
11-27-2018
08:46 AM
|
0
|
6
|
2525
|
POST
|
Thanks Xander and Martin for your suggestions. Sorry Xander I may have not explained the issue correctly. My ultimate goal here is to standardise a number of raster layers (696 of them). My first objective was to get the maximum value (a unique single value) for all those rasters. I've done that; but after examining the maximum value I realise that doing the mean of all the maximum values of all rasters would be a more accurate value (to later standardise them). What Martin says is what I need to do but I'm not familiar with numpy and arrays and I'm not quite sure how to proceed. I also wonder if there is a function in scipy that would do that directly? Below is just the start of the script but as I said I don't know how to proceed. import arcpy
import math
import os
import numpy
import scipy
from arcpy import env
arcpy.env.overwriteOutput=True
from arcpy.sa import*
arcpy.CheckOutExtension("Spatial")
env.workspace = r"D:\000_TEST_MAGNITUDE_summary\MAX_VAL_calculation\Vel_rasters.gdb
# List rasters and get MAX values
rasterlist1 = arcpy.ListRasters()
Vel_max = arcpy.GetRasterProperties_management(rasterlist1, "MAXIMUM")
# Create array and add result from above
Vel_array = arcpy.RasterToNumPyArray(rasterlist1)
... View more
11-27-2018
08:03 AM
|
0
|
1
|
2525
|
POST
|
Hi, As the title says, I'm trying to calculate in python the mean value out of all maximum values in a list of rasters (696) in a GDB. First thing would be to calculate all max values but I'm not sure how to "hold" all those values to then calculate the mean. Any help will be greatly appreciate it. Running ArcGis 10.5.1
... View more
11-27-2018
03:41 AM
|
0
|
15
|
3418
|
POST
|
It works like this: arcpy.env.extent = arcpy.Extent(-18040095.1961317, -9020047.34806998, 18039904.8038683, 9019952.65193002) Mollweide projection
... View more
07-16-2018
02:08 AM
|
0
|
0
|
1414
|
POST
|
Thanks for all the suggestions. I did it selecting first the points I wanted to move. Maybe not very elegant but it works. import arcpy
from arcpy import env
from arcpy.sa import *
FC1 = r"H:\NETcdf_TEST\TEST.gdb\rast2point" # This is the point FC after resampling (0.25/bilinear) and converting the shifted netcdf
FC2 = r"H:\NETcdf_TEST\TEST.gdb\rast2point2"
FC1new = r"H:\NETcdf_TEST\TEST.gdb\rast2point_new1"
FC2new = r"H:\NETcdf_TEST\TEST.gdb\rast2point2_new2"
FCfinal = r"H:\NETcdf_TEST\TEST.gdb\rast2pointFinal"
# Add XY coordinate fields and calculate field geometry
arcpy.AddXY_management(FC1)
# Make a copy of FC1
arcpy.Copy_management(FC1,FC2)
# Make layers from FCs
arcpy.MakeFeatureLayer_management(FC1, "FC1_lyr")
arcpy.MakeFeatureLayer_management(FC2, "FC2_lyr")
# Select point values <-180 (FC1) and point values >-180 (FC2)
arcpy.SelectLayerByAttribute_management("FC1_lyr", "NEW_SELECTION", '"POINT_X" <-180')
arcpy.SelectLayerByAttribute_management("FC2_lyr", "NEW_SELECTION", '"POINT_X" >-180')
# Write the selected features to a new featureclass
arcpy.CopyFeatures_management("FC1_lyr", FC1new)
arcpy.CopyFeatures_management("FC2_lyr", FC2new)
# Perform the move of FC1new
xOffset = 360.000
yOffset = 0.000
with arcpy.da.UpdateCursor(FC1new, ["SHAPE@XY"]) as cursor:
for row in cursor:
cursor.updateRow([[row[0][0] + xOffset,row[0][1] + yOffset]])
# Refresh GDB
arcpy.RefreshCatalog(r"H:\NETcdf_TEST\TEST.gdb")
# Merge FC1new and FC2new into FCfinal
arcpy.Merge_management([FC1new, FC2new], FCfinal)
... View more
07-11-2018
07:12 AM
|
0
|
0
|
699
|
POST
|
Hi, I need to shift by 360° points that are offset. It is just 7 columns of points in the West on the X axis that need to be shifted (see pictures and script below). I'm getting this error: TypeError: 'float' object has no attribute '__getitem__' Also, I'm not sure if I'm selecting/identifying the 7 columns of points I want correctly on my script. Any help will be much appreciated. import arcpy
import string
import math
FC = r"H:\NETcdf_TEST\TEST.gdb\rast2point"
x_shift = float(360)
with arcpy.da.UpdateCursor(FC, ['SHAPE@X']) as cursor:
for row in cursor:
cursor.updateRow([[row[0][7] + x_shift]])
del cursor
... View more
07-04-2018
02:57 AM
|
0
|
4
|
841
|
Title | Kudos | Posted |
---|---|---|
1 | 11-06-2015 05:13 AM | |
1 | 11-09-2015 01:25 AM | |
1 | 11-12-2014 05:27 AM |
Online Status |
Offline
|
Date Last Visited |
07-12-2022
09:52 AM
|