|
POST
|
There are a couple of ways to do this: One is if the field(s) and/or attribute(s) are identical between polygon layers, then you could use a group filter to filter both or set it so that one will filter the other based on the matching field and attributes. Another way is to create a relationship between the two features so that when you select one, it will show all related records to that particular feature. Another way is, if you are using Experience Builder, is you can set map actions to filter data based on matching attributes. There might be others that I have not suggested that someone else might know of but these should suffice for what you are trying to accomplish.
... View more
09-29-2023
10:05 AM
|
0
|
3
|
1930
|
|
POST
|
Hi, I am trying to figure out how to edit a named version using a sql script and I am not sure how to go about it. I can pull the named version information, but I am not sure how to update the information in the table. Here is what I have thus far. EXEC [Database].sde.edit_version 2, 1; -- opens edit session on version
EXEC [Database].sde.set_current_version 2; -- Sets version to access
BEGIN TRY
BEGIN TRANSACTION [Tran1]
MERGE [Database].[Featureclass_evw] as TargetTable
USING [Server].[Database].[dbo].[Table] as SourceTable
ON TargetTable.[MatchingColumn] = SourceTable.[MatchingColumn]
WHEN MATCHED THEN
UPDATE SET TargetTable.[ColumnA] = SourceTable.[ColumnB]
;
COMMIT TRANSACTION [Tran1] -- if successful will commit the transaction
END TRY
BEGIN CATCH -- if error occurs, will rollback the transaction
ROLLBACK TRANSACTION [Tran1]
END CATCH
EXEC [Database].sde.edit_version 2, 2; -- ends the edit session I have also tried this option below. EXEC [Database].sde.edit_version 2, 1; -- opens edit session on version
EXEC [Database].sde.set_current_version 2; -- Sets version to access
BEGIN TRY
BEGIN TRANSACTION [Tran1]
UPDATE [sdeowner].[Featureclass_evw]
SET [Field] = (
SELECT A.[Field]
FROM [Server].[Database].[dbo].[Table] AS A
JOIN [SDEOwner].[Featureclass_evw] ON [SDEOwner].[Featureclass_evw].[Field] = A.[Field]
WHERE EXISTS (
SELECT 1
FROM [Server].[Database].[dbo].[Table] AS A
WHERE [Field] = [SDEOwner].[Featureclass_evw].[Field]
)
)
COMMIT TRANSACTION [Tran1] -- if successful will commit the transaction
END TRY
BEGIN CATCH -- if error occurs, will rollback the transaction
ROLLBACK TRANSACTION [Tran1]
END CATCH
EXEC [Database].sde.edit_version 2, 2; -- ends the edit session I cannot seem to update the values based on these sql queries so I am stuck for the time being. Any help on this would be greatly appreciated.
... View more
09-28-2023
08:04 AM
|
0
|
0
|
1050
|
|
POST
|
Never mind. I finally figured out a solution which works really well.
... View more
09-27-2023
12:29 PM
|
0
|
0
|
2451
|
|
POST
|
Hi, I have been trying to figure out how to create an attribute rule to add a record in a related table based on certain criteria. I am not sure, since I am still learning quite a bit about arcade, how to go about it. I typically program in python, but I am trying to reduce the scripting that would be needed outside of a database when a simple attribute rule could accomplish a similar task. // Function for defining whether or not a fieldname exists in another feature
function ValidateFieldNames( InputFieldsA, InputFieldsB ){
var AFields = [ ]
var BFields = [ ]
for ( var i = 'name' in InputFieldsA ){
return Push( AFields, InputFieldsA[ i ] )
}
for ( var i = 'name' in InputFieldsB ){
return Push( BFields, InputFieldsB[ i ] )
}
for ( var Fieldname in BFields ){
var FieldnameIndex = IndexOf( AFields, InputFieldsB[ Fieldname ] )
if ( Includes( AFields, InputFieldsB[ Fieldname ] ) == False ){
return Erase( AFields, FieldnameIndex )
}
}
}
// Current date
var CurrentYear = Year( Date( Now() ) )
// Inspection year and date
var InspectedYear = $feature.FieldYear
var InspectedDate = $feature.FieldDate
// Inspection record table
var InspectionRecords = FeatureSetByName( $datastore, "Featureclass", ['*'] )
Console( InspectionRecords )
// Get array of recorded inspection year and get only unique years in descending order
var RecordedDates = FeatureSetByName( $datastore, "Table", ['InspectionDate'] )
var RecordedYears = Max( Year( RecordedDates ) )
// Get the matching fieldnames that exist in both features
var InspectionRecordSchema = Schema( InspectionRecords ).fields
var MatchingFieldnames = ValidateFieldNames( InspectionRecords, $feature )
// Loop through the update items to create a concatenated text value of items
// to create a single text line of dictionary values
var UpdateItems = NULL
for ( var field in MatchingFieldnames ){
var ConcatText = Concatenate( field, ' : ', $feature[ field ] )
iif ( UpdateItems == NUll, UpdateItems == ConcatText, Concatenate( UpdateItems, ',', ConcatText ) )
}
var UpdateItems = Dictionary( UpdateItems )
// If the current inspection year in the inspected hydrant layer
// is not in the inspection records table. Then add the record to
// the inspection table
if ( CurrentYear == InspectedYear && InspectedYear >= RecordedYears ){
return {
'result' : InspectedDate,
'edit': [
{
'classname' : "Featureclass",
'adds' : [
{
'objectID': $feature.ObjectID,
'attributes' : UpdateItems
}
]
}
]
}
} Any help with this would be greatly appreciated?
... View more
09-21-2023
07:26 AM
|
1
|
5
|
2577
|
|
POST
|
It might either be a schema lock issue or a permissions issue. I have encountered those before and it is something that will prevent you from editing the table using any script.
... View more
09-15-2023
12:13 PM
|
1
|
0
|
8026
|
|
POST
|
Hi @MarcSeliger , A couple of things. First, you typically don't edit the 'OBJECTID' field simply because that is merely an automated id that is added every time a new record is inserted into the table. You would typically any use any other field(s) for the update. You can use a search cursor or insert cursor for the 'OBJECTID' but that would be about it. Second, you can get the file path in pro by going into the catalog, selecting the feature class you want to update, and then copy the file path using Ctrl + Alt + P to get the full path. Third, the reason that you might not be able to update the other feature class is due to permission issues on the database or there might be a schema lock due to someone else editing. You should be able to also check the database to see if anyone else is potentially editing. I have also included a script that I have used to streamline editing that may or may not help. import arcpy, os
from arcpy import ListFields
from arcpy.da import (
Editor, SearchCursor, UpdateCursor, InsertCursor
)
UpdateFeatureClass = r'{ file path of the specified feature class or shapefile }'
SearchFeatureClass = r' { file path of the feature with object ids to update the other feature class }'
OIDField = ['OID@']
UpdateFeatureClassFields = [ field.name for field in ListFields( UpdateFeatureClass ) ]
SearchFeatureClassFields = [ field.name for field in ListFields( UpdateFeatureClass ) ]
# You can insert an if statement at the end if you need to get specific fields with particular names, types, or other field descriptions
# Optional matching fields
MatchingFields = list( set(UpdateFeatureClassFields).intersection(set(SearchFeatureClassFields)))
# update dictionary
UpdateRecords = { }
# search fields
MatchingFields = OIDField + MatchingFields
# specify search cursor
Searching = SearchCursor( SearchFeatureClass, MatchingFields )
with Searching as cursor:
for row in cursor:
UpdateRecords [ row[0] ] = row[1:]
# you can also use the search cursor in a single line as well if you did not know that
# UpdateRecords = { row[0]:row[1:] for row in Searching }
# update cursor
Updating = UpdateCursor( UpdateFeatureClass , MatchingFields )
# parent directory
ParentDirectory = os.pardir( UpdateFeatureClass )
# start editing featureclass
with Editor(ParentDirectory) as editor:
with Updating as cursor:
for row in cursor:
if row[0] in UpdateRecords:
recordupdates = UpdateRecords[ row[0] ]
cursor.updateRow(recordupdates) I am not quite sure what you are after but this should help depending on what you are trying to do.
... View more
09-15-2023
11:27 AM
|
0
|
2
|
8047
|
|
POST
|
Hi, I encountered an issue regarding creating a relationship feature class in a test sde database. The issue that I encountered is the script will create the relationship class, but for some reason none of the data relates for some reason. At first, I thought it might be due to none of the related features having data in them as a possibility. I ran the same script with data in both of the features and it worked. I don't know why this would be an issue or if anyone else has had similar issues, but I would like to know if there is a way to make certain that this won't happen again next time the script runs. # Import arcpy da modules
from arcpy.da import (
# Import functions/classes pertaining to editing features in databases
Editor as Editing, SearchCursor as Searching, InsertCursor as Inserting, UpdateCursor as Updating,
# Import functions/classes pertaining to looping or creating item lists
ListDomains, Walk, ListVersions, ListContingentValues
)
# Import arcpy management modules
from arcpy.management import (
# Creating features
CreateFeatureDataset as MakeDataset, CreateFeatureclass, CreateTable ,
# Feature field modifications
AddField, AlterField as ModifyField , DeleteField ,
# Creating, deleting, or modifying domains
CreateDomain, AlterDomain, AddCodedValueToDomain as AddCode, DeleteCodedValueFromDomain as DeleteCode, SetValueForRangeDomain as SetRange, DeleteDomain, AssignDomainToField, RemoveDomainFromField ,
# Attribute rules
EnableAttributeRules, DisableAttributeRules, AddAttributeRule, AlterAttributeRule, DeleteAttributeRule ,
# Creating feature relations
CreateRelationshipClass as MakeRelation, AddRelate, RemoveRelate ,
# Establishing roles and users
CreateRole, ChangePrivileges, CreateDatabaseUser, ChangePrivileges, UpdatePortalDatasetOwner ,
# Updating licensing information
UpdateEnterpriseGeodatabaseLicense as LicenseUpdate ,
# Enabling or disabeling editor tracking on features
EnableEditorTracking as TrackEdits, DisableEditorTracking as StopTrackEdits ,
# Managing versions
CreateVersion, ChangeVersion, AlterVersion, DeleteVersion , RegisterAsVersioned , UnregisterAsVersioned ,
# Creating contingent values
CreateFieldGroup , AlterFieldGroup , DeleteFieldGroup , AddContingentValue , RemoveContingentValue ,
# Add global ids
AddGlobalIDs ,
# Create database connections
CreateDatabaseConnection ,
# Manage layer symbology from existing layer
ApplySymbologyFromLayer ,
# Make a feature layer
MakeFeatureLayer , SaveToLayerFile
)
# Create relationship table between certain feature classes
def RelateFeatures( InputDatabase, RelateFeaturesDictionary ):
Tab = ' ' * 4
print ( f'Creating relationship classes for relations in { list( RelateFeaturesDictionary ) }' )
# Important variables
Relationships = 'Relationships'
Origin, Destination, ToLabel, FromLabel, Field = 'Origin', 'Destination', 'ToLabel', 'FromLabel', 'Field'
To, From, Both, Neither = 'FORWARD', 'BACKWARD', 'BOTH', 'NONE'
Attributed, NotAttributed = 'ATTRIBUTED', 'NONE'
Simple, Composite = 'SIMPLE', 'COMPOSITE'
OneCardinality, OneManyCardinality, ManyCardinality = 'ONE_TO_ONE', 'ONE_TO_MANY', 'MANY_TO_MANY'
# Important feature classes and tables
FeatureClasses = { filename : Combine( InputDatabase, filename ) for root, directory, filenames in Walk( InputDatabase, datatype='FeatureClass' ) for filename in filenames }
Tables = { filename : Combine( InputDatabase, filename ) for root, directory, filenames in Walk( InputDatabase, datatype='Table' ) for filename in filenames }
# Get all relationship feature classes
Relationships = { filename : Combine( InputDatabase, filename ) for root, directory, filenames in Walk(InputDatabase, datatype='RelationshipClass') for filename in filenames }
ValidateExistingRelationships = [ RelateName for RelateName in RelateFeaturesDictionary for ExistingRelation in Relationships if RelateName in ExistingRelation ]
# Create the relationships for each named relation in the dictionary
for Relation in RelateFeaturesDictionary:
OriginName = RelateFeaturesDictionary[ Relation ][ Origin ]
DestinationName = RelateFeaturesDictionary[ Relation ][ Destination ]
RelationshipClass = Combine( InputDatabase, Relation )
OriginFeature = None
DestinationFeature = None
OriginLabel = RelateFeaturesDictionary[ Relation ][ ToLabel ]
DestinationLabel = RelateFeaturesDictionary[ Relation ][ FromLabel ]
KeyField = RelateFeaturesDictionary[ Relation ][ Field ]
# Get the origin feature from either feature classes or tables
for Name in FeatureClasses:
Fullname = None
if '.' in Name:
Fullname = Name.split( '.' )[ -1 ]
if Fullname == OriginName:
OriginFeature = FeatureClasses[ Name ]
# Get the destination feature from either feature classes or tables
for Name in Tables:
Fullname = None
if '.' in Name:
Fullname = Name.split( '.' )[ -1 ]
if Fullname == DestinationName:
DestinationFeature = Tables[ Name ]
# Create the relationship class if the relationship class does not exist
if Relation not in ValidateExistingRelationships:
NewRelation = MakeRelation( OriginFeature, DestinationFeature, RelationshipClass, Simple, OriginLabel, DestinationLabel, To, OneManyCardinality, NotAttributed, KeyField, KeyField )
print ( f'{ Tab }{ NewRelation } has been created between { RootName( OriginFeature ) } as the origin and { RootName( DestinationFeature ) } as the destination' )
print ( '\n' )
return
# Core relationship features
Relationships = {
'Relationship Name' : {
Origin : FeatureA,
Destination : TableA,
ToLabel : 'To Message',
FromLabel : 'From Message',
Field : 'Selected Field Name'
}
}
# Create relationships
RelateFeatures( MainDatabase, Relationships )
... View more
09-13-2023
06:41 AM
|
0
|
3
|
2794
|
|
POST
|
Hi, I have a quick question regarding contingent values and the potential impacts that it may have on performance either with editing in the field or the database itself. I have a script that creates all potential combinations and adds them as contingent values. Depending on what limitations or restrictions I set, I get a varying number of possible outcomes ranging from 300 to over 1000. Here is part of the script that I have that creates all possible combinations and returns a list of strings that are then added as contingent values. from itertools import permutations, combinations
# Contingent values function
def CreateContingentStringValues( Fields, Condition, DomainType, DomainCodes, Constraints, SetNullConditions, ExistingValues ):
Equal, NotEqual, GreatThan, LessThan = '=', '!=', '>', '<'
FieldIndexing = { fieldname : index for index, fieldname in enumerate( Fields ) }
Combinations = None
if len( Fields ) >= 2:
if Condition == NotEqual:
Combinations = list( list( combinations( DomainCodes, len( Fields ) ) ) )
elif Condition == Equal:
Combinations = list( list( permutations( DomainCodes, len( Fields ) ) ) )
elif Condition in [ GreatThan, LessThan ]:
pass
ValidCombinations = []
if Combinations:
for Combination in Combinations:
ValidateCombinations = len( set( Constraints ).intersection( set( Combination ) ) ) < 2
CombinationOrder = [ Constraints[ value ] for value in Combination if value in Constraints ]
SortedOrder = sorted( CombinationOrder, reverse = True )
ValidateOrder = all( [ True if any( [ a == b, a > b ] ) else False for a, b in zip( SortedOrder, CombinationOrder ) ] )
if all( [ ValidateCombinations, SetNullConditions not in Combination, ValidateOrder ] ):
ValidCombinations += [ Combination ]
ValuesString = [ ]
if ValidCombinations:
for Combination in ValidCombinations:
FieldValueDict = dict( zip( Fields, Combination ) )
ListStrFieldNameValue = [ f'{ FieldName } { DomainType } { FieldValueDict[ FieldName ] }' for FieldName in FieldValueDict ]
StrValue = ';'.join( ListStrFieldNameValue )
if StrValue not in ExistingValues:
ValuesString += [ StrValue ]
if type( SetNullConditions ) is str:
ListStrFieldNameValue = [ f'{ FieldName } { DomainType } { SetNullConditions }' if FieldIndexing[ FieldName ] == 0 else f'{ FieldName } NULL { SetNullConditions }' for FieldName in FieldIndexing ]
StrValue = ';'.join( ListStrFieldNameValue )
if StrValue not in ExistingValues:
ValuesString += [ StrValue ]
return ValuesString It works but my concern is the impact that it may have on our field editors. Any help or input would be greatly appreciated.
... View more
09-07-2023
01:24 PM
|
1
|
0
|
1054
|
|
BLOG
|
Thank you very much. It is always a pleasure to help or be helped.
... View more
09-07-2023
01:16 PM
|
3
|
0
|
1308
|
|
POST
|
I have changed it from .gdb to .sde and it still returns a none value.
... View more
08-16-2023
09:37 AM
|
0
|
1
|
4156
|
|
POST
|
Hi, I ran into a bit of an issue regarding domain values from a list of domains in a database. I don't know if there are limitations regarding a .fgdb vs .sde databases, but I wanted to see if there was a way to get either the range values or the coded values from an .sde database. I wrote a script to access it, which seems to work partially, but I am not sure why it isn't working on an .sde database. Any help on this would be appreciated. import arcpy, os, datetime
from arcpy import ListFields, CreateFileGDB_management as CreateGDB, Point
from arcpy.da import Editor as Editing, SearchCursor as Searching, InsertCursor as Inserting, UpdateCursor as Updating, Walk, ListDomains as GetDomains
from arcpy.management import CopyFeatures as ReplicateFeature, CreateFeatureDataset as MakeDataset, CreateRelationshipClass as MakeRelation, CreateTable, AddField
from arcpy.conversion import ExportTable as ReplicateTable
from datetime import datetime, timedelta
from os import chdir as SetDirectory, mkdir as CreateDirectory
from os.path import basename as RootName, join as Combine, exists as Existing, dirname as ParentDirectory, isfile
# Get coded domains and descriptions for populating specific fields
def CodedDomains(Database, SpecifiedDomain):
DomainValues = None
if '.gdb' in Database:
for Domain in GetDomains(Database):
if Domain.name == SpecifiedDomain: DomainValues = Domain.codedValues
return DomainValues
CodedValues = CodedDomains(Database, DomainName)
for Code, Value in CodedValues.items(): print (f'"{Code}": "{Value}",')
... View more
08-16-2023
08:55 AM
|
0
|
3
|
4164
|
|
POST
|
Hi, General question, is it possible to use the attributes rules to insert records from one table to another using arcade. I can't seem to find any documentation stating that it is but I am hoping to get some answers. If this isn't possible, then I will stick with modifying my python script in conjunction with the other attribute rules that I have already created.
... View more
07-17-2023
08:39 AM
|
0
|
1
|
1936
|
|
POST
|
There are several things to consider when creating versions for the data and database that you are working with. Have a parent/default version that every version reconciles to. Determine how many editors will be editing the data. Determine how many versions you need to have? (Ex: version for field/external editors, version for internal editors, main qa/qc version, etc...? How do you want to set up your versioning. Versioning Tree: Combination of several child versions and parent versions under the default version Vertical versioning (Bottom to Top versioning): Child version to parent version to default version Combination of tree versioning and vertical versioning What kind of edits will each version be allowed to make (Ex: Complete or partial editing capabilities)? So there isn't a "recommended" approach simply because the way your organization is set-up can have many factors as to how to create the versions that you need/want. One of the many ways that helps determining how to create the versions is figuring out the importance of the data that you are working with using something similar to the method below. Determine your data's critical components. If you are the type of organization that has local/state/federal requirements, then you would need to figure out how to address those first. Determine what your needs and wants are. This will, in-turn, determine how to define the hierarchy for the versions that address those needs/wants/critical components. Based on the hierarchy, you can then decide whether to specify the version and how each version in the hierarchy will edit the data. The other key thing is you don't want to setup your versioning in such a way that you have too many editing versions nor too little editing versions. Having too many could cause roadblocks and having to little could have errors creeping into the default version. So lots to consider when wanting to create versions.
... View more
05-19-2023
05:49 AM
|
1
|
0
|
4005
|
|
POST
|
Have you tried using print statements to see what values are being returned? If not, then I would highly recommend doing so since it will tell you what values are actually returning. Otherwise it might be that there are errors in the data which would cause the sql clause to not work. Like I had mentioned before, it usually works best if you avoid sql clauses altogether since even a single character could cause the sql clause to either not return anything or not execute at all.
... View more
05-19-2023
04:19 AM
|
1
|
0
|
2609
|
|
POST
|
Hi, I am trying to run the closest facility layer and I wanted to know if there is a reason it takes an inordinate amount of time to append 95K records. I tried testing a small batch and it seems to work a bit faster when I do, but I am not sure why it takes a long time to append. Any reasons as to why that is? I would greatly appreciate any help on this.
... View more
05-18-2023
12:58 PM
|
0
|
0
|
795
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 2 weeks ago | |
| 1 | 05-07-2026 01:36 PM | |
| 1 | 02-10-2026 06:09 AM | |
| 1 | 03-04-2026 01:08 PM | |
| 1 | 02-24-2026 12:59 PM |
| Online Status |
Offline
|
| Date Last Visited |
Friday
|