POST
|
I was able to fix this by using the algorithm at rapidtables. Unlike the data given in the ESRI documentation (hue = 0 - 240, saturation = 0 - 255, value = 0 - 255) the actual HSV format is hue 0 - 360, saturation 0 - 100, value 0 - 100 The code is now: def colourHSVtoRGB(self,H,S,V):
# The ArcGIS HSV model is - Hue 0-360, Saturation Pct, Value Pct
# Algorithm from https://www.rapidtables.com/convert/color/hsv-to-rgb.html
hval = H
if hval == 360:
hval = 0
sval = S / 100
vval = V / 100
C = sval * vval
tr = abs((hval / 60 % 2) - 1)
X = C * (1 - tr)
if 0 <= H and H < 60:
R = C
G = X
B = 0
elif 60 <= H and H < 120:
R = X
G = C
B = 0
elif 120 <= H and H < 180:
R = 0
G = C
B = X
elif 180 <= H and H < 240:
R = 0
G = X
B = C
elif 240 <= H and H < 300:
R = X
G = 0
B = C
elif 300 <= H and H < 360:
R = C
G = 0
B = X
m = vval - C
R = int(round(255 * (R + m),0))
G = int(round(255 * (G + m),0))
B = int(round(255 * (B + m),0))
return R, G, B John
... View more
02-13-2024
05:18 PM
|
1
|
0
|
207
|
POST
|
I am trying to populate 3 fields in a feature class with the symbology colour in RGB. My conversion code takes the H, S and V values given by the layer.symbology.renderer.symbol.color function. A sample of the output from the color function is: {'HSV': [61, 50, 55, 100]} The values must be munged to cater for the ArcGIS colour model ; My code is: def colourHSVtoRGB(self,H,S,V):
# The ArcGIS HSV model is strange - Hue 0-240, Saturation 0 - 255, Value 0 - 255
from matplotlib.colors import hsv_to_rgb
# Convert hval to 360 and make it 0 - 1
hval = 3.6 * (H / 240)
sval = S / 255
vval = V / 255
invals = [hval, sval, vval]
rg = hsv_to_rgb(invals)
R = rg[0]
G = rg[1]
B = rg[2]
# Convert to 0 - 255
R = int(round((R * 255), 0))
G = int(round((G * 255), 0))
B = int(round((B * 255), 0)) Unfortunately this gives the incorrect RGB values. From a colour web site, the RGB for HSV = 61, 50, 55 should be 139, 140, 70, which also looks like the correct colour. My function outputs RGB values; 49, 55, 44 - clearly wrong. The input values to the matplotlib function are all 0 - 1. I'm sure my interpretation of the calculation for this input could use some improvement. Thanks, J
... View more
02-12-2024
07:06 PM
|
1
|
1
|
301
|
IDEA
|
I agree. For point based chainage markers the chainage text can be aligned with the direction of the line. E.G: Chainages However with line markers the best possible is horizontal: Horizontal It would be nice to be able to align the text based on a field value, as it is for points.
... View more
03-15-2023
09:24 PM
|
0
|
0
|
607
|
POST
|
It turns out the problem is with the layer grouping. I ran the following code: arpx = arcpy.mp.ArcGISProject("CURRENT")
thismap = arpx.activeMap
for layr in thismap.listLayers():
try:
longname = layr.longName
desc = arcpy.Describe(layr)
dty = desc.dataType
messages.addMessage(f"{longname} Type: {dty}")
lyrCIM = layr.getDefinition('V2')
layr.setDefinition(lyrCIM)
messages.addMessage(f"CIM saved")
except Exception as ex10:
messages.addMessage(f"Error: {ex10}") Which produced the (partial) output: Flooding\Flooding Information from Council\Upper South Creek Flood Study 2017 - Camden Council\20 Year ARI Type: FeatureLayer
Error:
Flooding\Flooding Information from Council\Upper South Creek Flood Study 2017 - Camden Council\50 Year ARI Type: FeatureLayer
Error:
Flooding\Flooding Information from Council\Upper South Creek Flood Study 2017 - Camden Council\100 Year ARI Type: FeatureLayer
Error:
Flooding\Flooding Information from Council\Upper South Creek Flood Study 2017 - Camden Council\200 Year ARI Type: FeatureLayer
Error:
Flooding\Flooding Information from Council\Upper South Creek Flood Study 2017 - Camden Council\500 Year ARI Type: FeatureLayer
Error:
Flooding\Flooding Information from Council\Upper South Creek Flood Study 2017 - Camden Council\PMF Type: FeatureLayer
CIM saved As you can see, only one layer (PMF) was able to save the CIM. The rest produced a non-existent error. I had a look at the 100 Year ARI .lyrx file and there didn't seem to be anything wrong with it. I removed the above layers from their groups and re-ran the code: 100 Year ARI Type: FeatureLayer
CIM saved
50 Year ARI Type: FeatureLayer
CIM saved
200 Year ARI Type: FeatureLayer
CIM saved
500 Year ARI Type: FeatureLayer
CIM saved
PMF Type: FeatureLayer
CIM saved All the CIM data was able to be saved. This does pose some interesting questions though. I wonder if ESRI could shed some light on it.
... View more
01-23-2023
06:55 PM
|
0
|
0
|
828
|
POST
|
Thanks Guys. The process will update the gdb of a layer source. The feature class name is the same. Here is the full code. def execute(self, parameters, messages):
gdbs = parameters[0].ValueAsText
gdbs = gdbs.replace("'", "")
source_gdbs = gdbs.split(';')
completecount = 0
missedcount = 0
try:
arpx = arcpy.mp.ArcGISProject("CURRENT")
thismap = arpx.activeMap
tot = len(thismap.listLayers())
arcpy.SetProgressor("step", "Layers", 0, tot, 1)
n = 0
messages.addMessage(f"Total Layers {str(tot)}")
# Scan the geodatabases
gdblist = self.scanGeodatabases(source_gdbs)
for layr in thismap.listLayers():
# Name and longName. Note that not all layers support name.
# If os.path.basename is used to get name, then it returns 2022 for a layer named 'The Layer (13/12/2022)'
longname = layr.longName
if '\\' in longname:
lset = longname.split('\\')
index = len(lset) - 1
lname = lset[index]
else:
lname = longname
hasdesc = False
hastype = False
hascatpath = False
try:
desc = arcpy.Describe(layr)
hasdesc = True
ltype = desc.dataType
hastype = True
catalogpath = ''
if hasattr(desc,'catalogPath'):
catalogpath = desc.catalogPath
hascatpath = True
#messages.addMessage(f"{ltype} {longname}")
except:
pass
arcpy.SetProgressorLabel(lname)
arcpy.SetProgressorPosition(n)
n += 1
isGroup = layr.isGroupLayer
if not isGroup and hastype and ltype != 'GroupLayer':
if ltype == "FeatureLayer" or ltype == "FeatureClass" or ltype == "RasterLayer" or ltype == "RasterDataset":
if hasattr(layr,'connectionProperties'):
connProp = layr.connectionProperties
# messages.addMessage(f"Type = {type(connProp)} End Type")
nType = False
try:
tst = connProp['dataset']
except Exception as ex:
nType = True
if nType:
messages.addMessage(f"Error: Layer {longname} connection contains a NoneType object")
missedcount += 1
else:
##connPropDict = {k: v for k, v in connProp.items() if k is not None and v is not None}
fcname = connProp['dataset']
# fcname = layr.connectionProperties['dataset']
# messages.addMessage(f"Layer FC: {fcname}")
# FC in gdblist
ingdb = [g for g in gdblist if g['FC'] == fcname and g['FORT'] == 'F']
if len(ingdb) > 0:
newconnprop = layr.connectionProperties
db = ingdb[0]['GDB'].strip()
newconnprop['connection_info']['database'] = db
layr.updateConnectionProperties(connProp, newconnprop)
messages.addMessage(f"{lname} Source updated {db}")
completecount += 1
else:
messages.addMessage(f"Layer {longname} not in databases")
missedcount += 1
elif hascatpath:
fcname = os.path.basename(catalogpath)
ingdb = [g for g in gdblist if g['FC'] == fcname and g['FORT'] == 'F']
if len(ingdb) > 0:
db = ingdb[0]['GDB'].strip()
dbname = os.path.basename(db)
currentgdb = os.path.dirname(catalogpath)
currentname = os.path.basename(currentgdb)
# messages.addMessage(f"Current GDB: {currentname}\nNew GDB: {dbname}")
lyrCIM = layr.getDefinition('V2')
dc = lyrCIM.featureTable.dataConnection
# layr.setDefinition(lyrCIM) <- Testing
dc.workspaceConnectionString = f"DATABASE={db}"
messages.addMessage(f"New Wkspace {dc.workspaceConnectionString}")
layr.setDefinition(lyrCIM)
messages.addMessage(f"{longname} Source updated {db}")
completecount += 1
else:
messages.addMessage(f"Layer {longname} not in databases")
missedcount += 1
else:
messages.addMessage(f"{ltype} Layer {longname} has no catalogPath or connection properties")
missedcount += 1
else:
messages.addMessage(f"Cannot process {ltype} layer {longname}")
missedcount += 1
messages.addMessage(f"Completed: {str(completecount)}. Missed {str(missedcount)}")
except Exception as ex:
exc_type, exc_obj, exc_tb = sys.exc_info()
err = f"Error: Line {exc_tb.tb_lineno} {ex}"
messages.addErrorMessage(f"{err}")
return
return
... View more
01-22-2023
01:13 PM
|
0
|
0
|
849
|
POST
|
The layr object is just the result of the listLayer() function: for layr in thismap.listLayers():
if layr.isGroupLayer:
continue None of the layers are joined.
... View more
01-19-2023
04:45 PM
|
0
|
0
|
874
|
POST
|
I am trying to change the data source geodatabase of ArcGIS Pro layers. The feature class name is unchanged. It is the general consensus to use connectionProperties for this, however I have a number of feature classes that do not have connectionProperties so I've elected to use CIM for these. if hasattr(layr,'connectionProperties'): Returns False. For the CIM, If I just write: lyrCIM = layr.getDefinition('V2')
layr.setDefinition(lyrCIM) It throws an error! The error message is the line number. Ugh. What I want to do is: lyrCIM = layr.getDefinition('V2')
dc = lyrCIM.featureTable.dataConnection
dc.workspaceConnectionString = f"DATABASE={newdb}"
layr.setDefinition(lyrCIM) Which throws the same (useless) error. My ArcGIS Pro version is 2.9.5
... View more
01-18-2023
03:45 PM
|
0
|
9
|
946
|
POST
|
A bit more detail on the error: Traceback (most recent call last): File "C:\Work\Python\User_Management\update_security_question.py", line 70, in <module> main() File "C:\Work\Python\User_Management\update_security_question.py", line 60, in main exusr[u].update(description='Here') File "C:\Users\mcglynnj\AppData\Local\Programs\Python\Python39\lib\site-packages\arcgis\gis\__init__.py", line 7723, in update ret = self._gis._con.post(path=url, File "C:\Users\mcglynnj\AppData\Local\Programs\Python\Python39\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 716, in post return self._handle_response(resp=resp, File "C:\Users\mcglynnj\AppData\Local\Programs\Python\Python39\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 504, in _handle_response data = resp.json() File "C:\Users\mcglynnj\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 900, in json return complexjson.loads(self.text, **kwargs) File "C:\Users\mcglynnj\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 346, in loads return _default_decoder.decode(s) File "C:\Users\mcglynnj\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Users\mcglynnj\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) Completed 0 updated. 0 don't exist. John
... View more
06-15-2021
02:28 PM
|
0
|
0
|
1341
|
POST
|
I have the same problem - updating the security question and answer. # Process users
upd_users = ["DaveG","PeterF"]
try:
count = 0
errorcount = 0
for upuser in upd_users:
print (upuser)
exusr = source.users.search(query=upuser)
if len(exusr) > 0:
try:
# update the user
for u in range (len(exusr)):
print(exusr[u].email) # Test
successor = exusr[u].update(description='Here')
print (f"{u.username} updated: {successor}")
if successor: count +=1
break
except Exception as ex:
print ("ERROR: {},{}".format(u.username,ex))
errorcount += 1
finally:
print ("Completed {} updated. {} don't exist.".format(str(count), str(errorcount))) As a test, updating the description I get the error: ERROR: DaveG,Expecting value: line 1 column 1 (char 0) Can someone point to the error I'm causing? Thanks
... View more
06-14-2021
10:35 PM
|
0
|
1
|
1346
|
POST
|
I doubt if ESRI will change this. Do they want users chopping and changing licences or keeping disabled ones which will require more 😁 licences?
... View more
06-03-2021
04:49 PM
|
0
|
0
|
1614
|
POST
|
Thanks Dan. This looks much better. import arcpy, os
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
layers = arcpy.mapping.ListLayers(mxd)
# Master featureclass names
PolylineMaster = 'PolylineMaster'
PointMaster = 'PointMaster'
PolygonMaster = 'PolygonMaster'
# Run each of point, polyline or polygon
doPoint = False
doPolyline = True
doPolygon = False
if doPoint == True:
lyrPtMaster = arcpy.mapping.ListLayers(mxd,PointMaster,df)[0]
if doPolyline == True:
lyrLineMaster = arcpy.mapping.ListLayers(mxd,PolylineMaster,df)[0]
if doPolygon == True:
lyrPolyMaster = arcpy.mapping.ListLayers(mxd,PolygonMaster,df)[0]
for lyr in layers:
lyrName = lyr.name
if lyrName == PolylineMaster or lyrName == PointMaster or lyrName == PolygonMaster:
continue
else:
print(lyrName)
desc = arcpy.Describe(lyr)
path = arcpy.Describe(lyr).catalogPath
print(path)
if desc.shapeType == "Point" and doPoint == True:
arcpy.mapping.UpdateLayer(df,lyr,lyrPtMaster,False)
elif desc.shapeType == "Polyline" and doPolyline == True:
arcpy.mapping.UpdateLayer(df,lyr,lyrLineMaster,False)
elif desc.shapeType == "Polygon" and doPolygon == True:
arcpy.mapping.UpdateLayer(df,lyr,lyrPolyMaster,False)
# Reset the data source and the layer name - both of which have been changed to the Master
lyr.replaceDataSource(path,'FILEGDB_WORKSPACE',lyrName,True)
print(lyrName)
lyr.name = lyrName
print(lyr.name)
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
del mxd
... View more
02-16-2021
02:51 PM
|
0
|
0
|
701
|
POST
|
I have an mxd file with about 80 layers. Each layer has to be updated with a standard symbology and labeling. If I use the arcpy.ApplySymbologyFromLayer_management it only updates the symbology. I want to up update everything. When I use the arcpy.mapping.UpdateLayer function it does exactly what I want. However it changes the layer name and the data source. I'm trying to run UpdateLayer and then change the name and datasource back. Unfortunately when I run Layer.replaceDataSource for a layer it changes all the layers in the map. This code is posted raw because I can't find the Code tag.... import arcpy, os mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0] layers = arcpy.mapping.ListLayers(mxd) # Master featureclass names PolylineMaster = 'PolylineMaster' PointMaster = 'PointMaster' PolygonMaster = 'PolygonMaster' # Run each of point, polyline or polygon doPoint = False doPolyline = True doPolygon = False if doPoint == True: lyrPtMaster = arcpy.mapping.ListLayers(mxd,PointMaster,df)[0] if doPolyline == True: lyrLineMaster = arcpy.mapping.ListLayers(mxd,PolylineMaster,df)[0] if doPolygon == True: lyrPolyMaster = arcpy.mapping.ListLayers(mxd,PolygonMaster,df)[0] for lyr in layers: lyrName = lyr.name if lyrName == PolylineMaster or lyrName == PointMaster or lyrName == PolygonMaster: continue else: print(lyrName) desc = arcpy.Describe(lyr) #path = arcpy.Describe(lyr).catalogPath # Full path - doesn't work path = arcpy.Describe(lyr).path # GDB path print(path) if desc.shapeType == "Point" and doPoint == True: arcpy.mapping.UpdateLayer(df,lyr,lyrPtMaster,False) elif desc.shapeType == "Polyline" and doPolyline == True: arcpy.mapping.UpdateLayer(df,lyr,lyrLineMaster,False) elif desc.shapeType == "Polygon" and doPolygon == True: arcpy.mapping.UpdateLayer(df,lyr,lyrPolyMaster,False) # Reset the data source and the layer name - both of which have been changed to the Master lyr.replaceDataSource(path,'FILEGDB_WORKSPACE',lyrName,True) print(lyrName) lyr.name = lyrName print(lyr.name) arcpy.RefreshActiveView() arcpy.RefreshTOC() del mxd I am using ArcGIS 10.6 Can replaceDataSource be used to replace just one layer's data source?
... View more
02-14-2021
06:14 PM
|
0
|
3
|
795
|
POST
|
A multipatch is not considered to be closed until the start point has been added at the end of the list of points.
... View more
04-07-2016
09:29 PM
|
0
|
0
|
509
|
POST
|
Hi Rami, I am doing the same thing. When you do the SDE upgrade it also upgrades all the schemas in the same database. That is why the SDE schema has to have all the 'ANY' permissions. You only have to do new upgrades for separate databases. The upgrade reports that John is already in an acceptable release because it was upgraded by the SDE one.
... View more
10-12-2015
05:25 PM
|
0
|
0
|
512
|
POST
|
I think the problem is due to the fact that the spatial reference is stored in the shape field. When constructing a featureclass an IGeometryDef object is set with the Spatial Reference. If you change the spatial reference of an instance of a geometry, ArcGIS refuses to store it because the new and the existing spatial refs don't match. You can change the coordinates to be the same as the reprojected geometry but the spatial reference cannot change. It also means looping through all the vertices of each geometry to change them. To change the spatial reference of a featureclass would require removing the shape field and replacing it with one having the new spatial reference. By doing this you lose the original geometry. It looks like the only way of doing a reproject is to create a new featureclass with the new spatial reference and then copy the old one to it with the geometry reprojected using the IGeometry.Project method.
... View more
08-11-2015
03:34 PM
|
0
|
1
|
528
|
Title | Kudos | Posted |
---|---|---|
1 | 02-13-2024 05:18 PM | |
1 | 02-12-2024 07:06 PM |
Online Status |
Offline
|
Date Last Visited |
02-13-2024
11:00 PM
|