|
POST
|
Well after doing a BUNCH more digging, I found this: Table source from ArcGIS Server | ArcGIS API for JavaScript 3.27 It spelled out that you need to put dynamicLayer after your MapServer in the URL specified for the feature layer you're trying to create instead of the ID number. So when specifying the feature layer, the URL should look like this (the rest of the code was fine): var hbMgmtTractFL = new FeatureLayer("https://stuff_here/rest/services/HabitatMonitoring/HabitatData/MapServer/dynamicLayer", { .....}); Additionally, I added a set definition expression method to the end of my code that worked just fine. I didn't even have to prefix the field with HabitatManagement.dbo.MgmtAttrb like I thought I would. The "YearTreated" field exists in the MgmtAttrb table. hbMgmtTractFL.setDefinitionExpression("YearTreated = " + currentYear);
... View more
02-21-2019
12:34 PM
|
0
|
0
|
1103
|
|
POST
|
I'm looking to join a table to a polygon layer and I can't get the fields to transfer over. I'm sure there's something in my syntax that's messed up, but I can't figure out what it is. The goal of this process is to use a value from a field in the table to set the definition expression on the polygon layer (which I think I can do if the tables are joined?). It could be that I didn't create the workspaceId on the correct layer too... Or maybe I need to create a dynamic layer first? I'm utterly confused when it comes to dynamic layers. This is what I currently have: //Join habitat management attributes to the habitat management polygon layer
var joinDataSource = new JoinDataSource();
joinDataSource.joinType = 'left-inner-join';
joinDataSource.leftTableKey = "HabitatManagement.dbo.MgmtTracts.MgmtTractID";
joinDataSource.rightTableKey = "HabitatManagement.dbo.MgmtAttrb.MgmtTractID";
leftTableSource = new LayerMapSource({
mapLayerId: 3
});
var rightTableSource = new LayerDataSource();
rightTableSource.dataSource = new TableDataSource({
workspaceId: "hmgmtAttrb",
dataSourceName: "HabitatManagement.dbo.MgmtAttrb"
});
joinDataSource.leftTableSource = leftTableSource;
joinDataSource.rightTableSource = rightTableSource;
var lyrDataSource = new LayerDataSource();
lyrDataSource.dataSource = joinDataSource;
//Add the habitat management tract feature layer
var hbMgmtTractFL = new FeatureLayer("https://stuff_here/rest/services/HabitatMonitoring/HabitatData/MapServer/3", {
refreshInterval: 10,
visible: false,
source: lyrDataSource,
outFields: ["*"]
});
hbMgmtTractFL.setMinScale(500000);
hbMgmtTractFL.setSelectionSymbol(selectionSym); The JS runs without errors in the console, and I can see the source comes through: When I look at the fields though, I only see the fields of the polygon layer listed. In my server manager, I've set up the workspaceId on a connection with the HabitatManagement geodatabase instead of the HabitatMonitoring geodatabase. The map service I've set up the workspaceId on resides in the HabitatMonitoring folder. Would that cause an issue? The "MgmtTracts" and "MgmtAttrb" layer (the layers to be joined) reside in my HabitatManagement geodatabase which is why I created the workspaceId using that connection.
... View more
02-21-2019
07:14 AM
|
0
|
1
|
1230
|
|
POST
|
That did the trick, thanks. codeblock = """def ID():
import uuid
return '{' + str(uuid.uuid4()) + '}'"""
expression = 'ID().upper()'
arcpy.CalculateField_management(mgmtTractFL, 'MgmtTractID', expression, 'PYTHON', codeblock)
... View more
02-21-2019
06:46 AM
|
1
|
0
|
1577
|
|
POST
|
I have a service that chooses whether to give a field one value or another depending on what's present in the data already. When I run the python script outside of the server, it runs fine. When I run it on the server, it fails because it doesn't recognize the uuid module in the code block. I think it's treating uuid as a string, but to use code blocks you pass in the whole code block as a string. Has anybody successfully used code blocks in their GP services? def getTractID(isDuplicate):
import uuid
if isDuplicate == 'dupe':
tractID = '{' + str(uuid.uuid4()) + '}'
tractID = tractID.upper()
arcpy.RemoveJoin_management(mgmtTractFL)
with arcpy.da.UpdateCursor(mgmtTractFL, 'MgmtTractID') as uCursor:
for row in uCursor:
row[0] = tractID
uCursor.updateRow(row)
del uCursor
arcpy.AddJoin_management(mgmtTractFL, 'OBJECTID', duplicatePolys, 'IN_FID')
else:
codeblock = """def ID():
return '{' + str(uuid.uuid4()) + '}'"""
expression = 'ID().upper()'
arcpy.CalculateField_management(mgmtTractFL, 'MgmtTractID', expression, 'PYTHON', codeblock) On my server it converts 'ID().upper()' into a g_ESRI_variable. I still don't get why it would affect it's efficacy though. The 'expression' variable would still be a string. g_ESRI_variable_3 = u'ID().upper()'
g_ESRI_variable_4 = u'MgmtTractID'
def getTractID(isDuplicate):
import uuid
if isDuplicate == 'dupe':
#stuff
else:
codeblock = """def ID():
return '{' + str(uuid.uuid4()) + '}'"""
expression = g_ESRI_variable_3
arcpy.CalculateField_management(mgmtTractFL, g_ESRI_variable_4, expression, 'PYTHON', codeblock) If this can't be figured out, I can always use a cursor but I figure CalculateField would be faster when there's 1000+ records.
... View more
02-14-2019
07:07 AM
|
0
|
3
|
1724
|
|
POST
|
Field mapping is super confusing in arcpy. It took me a while to figure it out switching back and forth between the FieldMappings and FieldMap help documents.
... View more
02-08-2019
10:28 AM
|
0
|
0
|
1668
|
|
POST
|
So I had assumed that when you use "NO_TEST" it would default to using whatever common fields are there. Turns out you have to actually use field map objects. So this is what I ended up with: fieldmap = arcpy.FieldMappings()
fieldmap.addTable(db_mgmtTractFC)
fieldmap.addTable(mgmtTractFL)
fieldmap.removeAll()
fm_TractID = arcpy.FieldMap()
fm_TractID.addInputField(db_mgmtTractFC, "MgmtTractID")
#I had a joined table,so I had to specify the field by putting the name of
#the layer at the beginning of the field name
fm_TractID.addInputField(mgmtTractFL, "AL_MgmtTracts_Template.MgmtTractID")
fieldmap.addFieldMap(fm_TractID)
arcpy.Append_management(mgmtTractFL, db_mgmtTractFC, 'NO_TEST', fieldmap)
... View more
02-07-2019
12:56 PM
|
0
|
1
|
1668
|
|
POST
|
I am using a FGDB feature class that has a field called "MgmtTractID" of string type. It has the exact same properties and name as a field in my feature class in an SDE geodatabase. Unfortunately, the attributes from MgmtTractID in my FGDB will not transfer to the SDE MgmtTractID field. I'm not sure why, if I use the Append tool (with selections on my FGDB feature class) in the GUI, it works fine. I use "NO_TEST" because some of the fields aren't common between the two feature classes. I have also checked with a search cursor that my feature layer contains the values I would like to transfer. arcpy.Append_management(mgmtTractFL, db_mgmtTractFC, 'NO_TEST') The documentation for the Append tool states this: Map layers can be used as Input Datasets. If a layer has a selection, only the selected records (features or table rows) are used by the Append tool. So why doesn't it work?
... View more
02-07-2019
12:26 PM
|
0
|
4
|
1765
|
|
POST
|
Alright, I figured this out. It had to do with the fact that I joined the layer prior to trying to use a search cursor on it. When you join tables, the name of the feature class get appended to the beginning of the field name so you can tell which field goes to which table (ex: MgmtTracts.MgmtTractID). When I change my search cursor line to specify it with the feature class name with arcpy.da.searchCursor(mgmtTractFL, 'MgmtTracts.MgmtTractID') as sCursor: it worked.
... View more
02-07-2019
11:58 AM
|
0
|
0
|
2838
|
|
POST
|
I have a script that creates a new field for the feature class, then creates a feature layer out of that FC, does a join, calculates stuff, does selections, etc. Then I try to run a search cursor on that feature layer and it says that it cannot find the field I added. If I change the input layer from the feature layer to the feature class instead, it can find the field, so we know that field does indeed exist. I would just use the feature class but then the cursor doesn't honor my selections. I don't get why it can't find the field. #Add MgmtTractID field
arcpy.AddField_management(mgmtTractFC, 'MgmtTractID', 'Text', '#', '#', 50)
#Create feature layer
mgmtTractFL = arcpy.MakeFeatureLayer_management(mgmtTractFC, 'mgmtTractFL')
#Do a bunch of stuff...
#...
#...
#Make selections
arcpy.SelectLayerByAttribute_management(mgmtTractFL, 'NEW_SELECTION')
expression = createFIDQuery(FID_SubMaster)
arcpy.SelectLayerByAttribute_management(mgmtTractFL, 'REMOVE_FROM_SELECTION', expression)
with arcpy.da.SearchCursor(mgmtTractFL, 'MgmtTractID') as sCursor:
for row in sCursor: ####### Error here: Cannot find field MgmtTractID ########
print row[0] If I change the search cursor line to search the actual feature class the feature layer is based on with arcpy.da.SearchCursor(mgmtFC, 'MgmtTractID') as sCursor:
it works just fine and can find the field. I wish I could list fields of a feature layer but I can't so I'm stuck on what to do and how to debug this thing. UPDATE: I just tested this with other fields in my feature class and it can't find any of those either. I know you can use search cursors on feature layers so...
... View more
02-07-2019
11:47 AM
|
0
|
1
|
3373
|
|
POST
|
This is probably a dumb question as I'm just looking into using ArcCollector, but can you actually fire a python script within collector? For instance, say a user input a wind value in mph but we want to bin that value into some integer like 1, 2, or 3 based on differing ranges of mph (there's probably some other way to do this in the app without scripting, but just humor me here). Can you set it up to do that in real time when collecting features or is that kind of thing only doable after they have synced to the database or AGOL or whatever it is? Basically, they'd fill out a field which would trigger the script. Also important to note, they'd largely be collecting data offline and need to sync later.
... View more
01-18-2019
10:54 AM
|
0
|
1
|
1199
|
|
POST
|
I have a feature class where you draw a polygon and put in an ID. I also have a table that is related to this feature class by the ID field. How can I make it so I cannot enter a record into the table for an ID that doesn't exist? Example: Feature class Polygon ID 1 Polygon ID 2 Table Record ID 5 <----- I want to make this impossible to do Record ID 1 Record ID 1 Record ID 2 Record ID 1 I cannot enforce a domain as the IDs can be unlimited. You can't auto-populate fields or domains. I have a relationship class defined between the feature class and table but I don't think this can do what I am describing. EDIT: So it looks like the above is not possible via normal ArcMap avenues... would this be possible using Attribute Assistant? If so, what's the rule look like? I have used a "CREATE_LINKED_RECORD" rule that should enforce a PK/FK relationship, but it doesn't seem to be doing so. This is the rule I have: Table Name: State_MgmtTracts Field Name: <empty> Value Method: CREATE_LINKED_RECORD Value Info: State_MgmtAttrb|ID_Number|ID_Number|ID_Number|ID_Number On Create: True On Change (Attribute): False On Change (Geometry): False Manual Only: False Rule Weight: 1
... View more
01-15-2019
10:03 AM
|
0
|
0
|
732
|
|
POST
|
Alright - so close to working. Now I am left with two files right before the script errors out and it's getting hung up on deleting the "timestamps" file saying something else is accessing it. Right before the script errors out I have a _gdb lock file, it disappears once I close the console window where the script is running (which effectively stops the script).
... View more
01-03-2019
07:07 AM
|
0
|
3
|
3930
|
|
POST
|
Thanks, I will give that a shot because I am not using "del" statements right now after cursors. I also discovered through debug that some locks are actually persisting but disappear once the script completes with an error (which makes perfect sense now that I think about it...).
... View more
01-03-2019
06:54 AM
|
0
|
0
|
3930
|
|
POST
|
I have created a script where at the end of it, I transfer records from and FGDB to a SDE database. I use the editor and believe I stop the operations correctly. At the end of this process, there are no longer any lock files in my FGDB. When I go to delete the entire FGDB, it gets hung up on .gdbtable and the deletion process will stop (and I assume if that got fixed, it would get hung up on .gdbindexes, .gdbtablx, or .spx). I have tried compacting the database and this does not work. I have tested that I can obtain a schema lock on one of the feature classes inside the FGDB and it says I can, I think this indicates that exclusive locks are not present. When I look in file explorer, there are no locks present. I really need an arcpy solution to this problem so the FGDB deletes successfully. This is my code, starting at the editor process. Before this piece of code, I use search cursors on the FGDB with the with/as notation (so cursor locks should be deleted automatically). #Instiantiate an editing object on the HbMonitoring database.
editor = arcpy.da.Editor(hb_db_con)
try:
arcpy.AddMessage("Updating Observers table with new observers...")
editor.startEditing(False, False)
editor.startOperation()
#Create insert cursor to insert new observers into the Observers database table
with arcpy.da.InsertCursor(obsvTable, obsvFields) as obsvCursor:
for item in newObservers:
obsvCursor.insertRow(item)
editor.stopOperation()
editor.stopEditing(True)
except:
#do stuff
try:
arcpy.AddMessage("Copying data to Patches table...")
editor.startEditing(False, False)
editor.startOperation()
#Create insert cursor to insert new rows into the Patches table
with arcpy.da.InsertCursor(PatchesFC, icFields) as iCursor:
arcpy.AddMessage("Inserting patch row...")
for item in patchInsert:
iCursor.insertRow(item)
editor.stopOperation()
editor.stopEditing(True)
except:
#do stuff
try:
arcpy.AddMessage("Copying data to Protective Cover table...")
editor.startEditing(False, False)
editor.startOperation()
#Create insert cursor to insert new rows into the ProtectiveCover table
with arcpy.da.InsertCursor(proCovFC, iPCFields) as pcCursor:
for item in pcInsert:
pcCursor.insertRow(item)
editor.stopOperation()
editor.stopEditing(True)
except:
#do stuff
#Delete the scratch folder and scratch GDB
#If working with database from ArcMap interface
if "C:\Users" in scratchFolder:
arcpy.AddMessage("Deleting scratch folder...")
shutil.rmtree(scratchFolder)
arcpy.Compact_management(scratchGDB)
arcpy.AddMessage("Deleting scratch GDB...")
shutil.rmtree(scratchGDB)
These are the files that are left after I attempt to delete the FGDB (ignore the "VLC media file" - it's just Windows assuming it knows what program to open .spx files in)
... View more
01-03-2019
06:17 AM
|
0
|
6
|
4527
|
|
POST
|
I figured it out. The proxy folder does sit in the application, however when I run it in the development environment it doesn't take the name of the application into account, so the proxyRule in my JS needed to be tweaked a little: //Got rid of the appName before the /proxy in proxyUrl property
urlUtils.addProxyRule({
urlPrefix: "https://www.mydomain.org",
proxyUrl: "/proxy/proxy.ashx"
}); Works with this in proxy config file: <!--For testing in development environment-->
<ProxyConfig allowedReferers="*"
mustMatch="true"
logFile="proxyLog.txt"
logLevel="Warning">
<serverUrls>
<serverUrl url="https://www.mydomain.com/myserver/rest/services/HabitatManagement/HabitatManagement/GPServer"
username="xxx"
password="xxx"
matchAll="true"/>
<serverUrl url="https://www.mydomain.com/myserver/rest/services/HabitatMonitoring/HabitatData/MapServer"
username="xxx"
password="xxx"
matchAll="true" />
<serverUrl url="https://www.mydomain.com/myserver/rest/services/HabitatMonitoring/HabitatClassification/GPServer"
username="xxx"
password="xxx"
matchAll="true" />
<serverUrl url="https://www.mydomain.com/myserver/rest/services/PrintHabitatMaps/PrintHabitatMap/GPServer"
username="xxx"
password="xxx"
matchAll="true" />
</serverUrls>
</ProxyConfig>
... View more
11-26-2018
12:37 PM
|
0
|
0
|
8012
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-18-2020 10:31 AM | |
| 2 | 09-16-2025 02:17 PM | |
| 3 | 09-12-2025 09:26 AM | |
| 1 | 08-16-2023 05:11 PM | |
| 1 | 02-27-2024 06:48 AM |
| Online Status |
Offline
|
| Date Last Visited |
09-16-2025
02:16 PM
|