|
POST
|
Might be drawing at straws here: input_Featureclass = r"E:/ArcGISProjects/County/cccc.sde/MultiPartPoly"
input_Table = r"E:/ArcGISProjects/County/cccc.sde/AttributeTable"
relatedTables = arcpy.ListTables(input_Table)
# Create update cursor
with arcpy.da.InsertCursor(input_Featureclass, ['SHAPE@', 'ID']) as cursor:
# Start an edit operation
edit.startOperation()
# Perform edits
## CREATE THE NEW MULTI PART POLYGON IN THE FC
for cursors in cursor:
cursor.insertRow([geometries[0], validGuid])
for relatedTable in relatedTables:
with arcpy.da.InsertCursor(input_Table, ['ID', 'somefieldID']) as cursor2:
cursor2.insertRow([validGuid, 1520])
del cursor2
## Delete cursor object
del cursor
... View more
04-22-2020
01:25 PM
|
0
|
1
|
1156
|
|
POST
|
I have a Feature Class and a Table and a Relationship Class relating them via GlobalID I want to write to the Feature Class (geometry and a couple attributes) I also want to write to the related table (few attributes) Are there any simple examples of how to write to them via arcPy? I can write to the Feature Class like the below BUT how do I write to the related Table at the same time? workspace = r"E:/ArcGISProjects/CountySelection/cccc.sde"
edit = arcpy.da.Editor(workspace)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(False, False)
print "edit started"
# Create update cursor
with arcpy.da.InsertCursor(inputFeatureclass, ['SHAPE@', 'ADDRESSgeocode', 'DISTANCEparameter', 'UNIQUEIDparameter', 'COUNTYLIST', 'ID']) as cursor:
# Start an edit operation
edit.startOperation()
# Perform edits
## CREATE THE NEW MULTI PART POLYGON IN THE FC
cursor.insertRow([geometries[0], searchAddress, searchDistance, searchid, txt_list, validGuid])
## Delete cursor object
del cursor
# Stop the edit operation.
edit.stopOperation()
# Stop the edit session and save the changes
edit.stopEditing(True)
print "edit ended"
... View more
04-22-2020
12:33 PM
|
0
|
2
|
1216
|
|
POST
|
I went in and removed the Relationship Class from the Database Republished the Service and the GP Tool Service Reran my code from JavaScript to send the GP Tool a parameter and everything worked perfect... So it seems that the Relationship Class is causing the error....Not sure where or what I have to modify to get this to work with a Relationship class.... QUESTIONS: Does the Python code need to change to handle the Relationship Class??? How would I write to the Feature Class as seen below and then write to the related table as well... Say I am creating anew feature and pass it the geometry and fields as seen below. Then I update a Field (Field1) in the related table with the 'UnqiueID' OR Is my issue on the JavaScript side??? I cant see how that would be the case but the Relationship Class is definitly causing the error... workspace = r"E:/ArcGISProjects/CountySelection/cccc.sde"
edit = arcpy.da.Editor(workspace)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(False, False)
print "edit started"
# Create update cursor
with arcpy.da.InsertCursor(inputFeatureclass, ['SHAPE@', 'ADDRESSgeocode', 'DISTANCEparameter', 'UNIQUEIDparameter', 'COUNTYLIST', 'UnqiueID']) as cursor:
# Start an edit operation
edit.startOperation()
# Perform edits
## CREATE THE NEW MULTI PART POLYGON IN THE FC
cursor.insertRow([geometries[0], searchAddress, searchDistance, searchid, txt_list, validGuid])
## Delete cursor object
del cursor
# Stop the edit operation.
edit.stopOperation()
# Stop the edit session and save the changes
edit.stopEditing(True)
print "edit ended"
... View more
04-22-2020
08:28 AM
|
0
|
1
|
1317
|
|
POST
|
This is the error I am getting.....funny though when I run it from the GP Tool in ArcCatalog it runs fine
... View more
04-22-2020
07:06 AM
|
0
|
2
|
1317
|
|
POST
|
I had a python script that I published to a service. I was calling that service as such below and everything was working great. In the database i created a table and then a relationship class that references the Feature Class I was previously updating. Immediately this started throwing errors when I tried to run the python script calling for an edit session. I modified the python script to include an edit start and edit close I can now successfully run this script from ArcCatalog After running from ArcCatalog I republished this to a service As I have been doing all along I call this service and pass it a parameter. Now the job fails. Not sure why. I can manually run this from ArcCatalog but not when I call from JavaScript like I did in the past. Do I have to do something differently now that this Feature Class I am trying to write too is a part of a Relationship Class????? btnGISPush_Click: function () {
var dictstring = document.getElementById(JSONstring).value;
var params1 = {
request: dictstring
};
window.gpJSON.execute(params1).then(function (resultVal) {
console.log(resultVal.results[0].value);
var finalGPResults = resultVal.results[0].value;
},
function (err) {
console.log(err);
}
);
}
... View more
04-22-2020
05:25 AM
|
0
|
3
|
1361
|
|
POST
|
I think I got it working.....maybe a refresh or reopening of ArcCatalog????? Testing now so hold on...thin it worked two times workspace = r"E:/ArcGISProjects/CountySelection/cccc.sde"
edit = arcpy.da.Editor(workspace)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(False, False)
print "edit started"
# Create update cursor
with arcpy.da.InsertCursor(inputFeatureclass, ['SHAPE@', 'ADDRESSgeocode', 'DISTANCEparameter', 'UNIQUEIDparameter', 'COUNTYLIST', 'NWTLID']) as cursor:
# Start an edit operation
edit.startOperation()
# Perform edits
## CREATE THE NEW MULTI PART POLYGON IN THE FC
cursor.insertRow([geometries[0], searchAddress, searchDistance, searchid, txt_list, validGuid])
## Delete cursor object
del cursor
# Stop the edit operation.
edit.stopOperation()
# Stop the edit session and save the changes
edit.stopEditing(True)
print "edit ended"
... View more
04-21-2020
04:16 PM
|
0
|
0
|
2199
|
|
POST
|
I change the second argument to False but will not go.... This is not versioned data It is a Feature Class with a relationship Class to a table # Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(False, False)
... View more
04-21-2020
01:26 PM
|
0
|
1
|
2199
|
|
POST
|
I have a python script that has been working fine for some time. I added a table and a relationship class to my database connecting to the Feature Class I was updating.....and now the python script is complaining that it cannot add outside an edit session. My python script accepts a json string that can have multiple updates or just 1 I added some Start Edit and Stop Edit code and its still not working and giving me another error If I modify my edit string to this to include the Feature Class that has the relationship class edit = arcpy.da.Editor(r"E:/ArcGISProjects/CountySelection/cccc.sde/MultiPartPoly") I get this error Executing: createNWTLGEometryJSONJays "{"employees":[{"address":"1520 Split Oak Ln, Henrico, Virginia, 23229","distance":"10", "id" : "1a35172e071f4a33b191172a9b4b02ae" },{"address":"1341 Research Center Dr Blacksburg, VA 24060","distance":"9", "id" : "6a35172e071f4a33b191172a9b4b02ae" }]}"
Start Time: Tue Apr 21 15:42:10 2020
Running script createNWTLGEometryJSONJays...
Failed script createNWTLGEometryJSONJays...
Traceback (most recent call last):
File "E:\Projects\Selection\Python\county.py", line 124, in <module>
edit = arcpy.da.Editor(r"E:/ArcGISProjects/CountySelection/cccc.sde/MultiPartPoly")
RuntimeError: cannot open workspace
Failed to execute (createNWTLGEometryJSONJays).
Failed at Tue Apr 21 15:42:11 2020 (Elapsed Time: 1.50 seconds) import arcpy
import requests
import json
import uuid
dataInputParameter1 = arcpy.GetParameterAsText(0)
# {"employees":[{"address":"1520 Split Oak Ln, Henrico, Virginia, 23229","distance":"10", "id" : "1a35172e071f4a33b191172a9b4b02ae" },{"address":"1341 Research Center Dr Blacksburg, VA 24060","distance":"9", "id" : "6a35172e071f4a33b191172a9b4b02ae" }]}
textDict = json.loads(dataInputParameter1)
# DELETE ALL ROWS FROM THE FINAL DATASET
#arcpy.DeleteRows_management(r"E:/ArcGISProjects/CountySelection/ccccc.sde/MultiPartPoly_WebMercatorAux")
langs = []
for employee in textDict['employees']:
varsearchAddress = employee["address"]
varsearchDistance = employee["distance"]
varsearchid = employee["id"]
print ("address: " + varsearchAddress)
print ("distance: " + varsearchDistance)
print ("uniqueid: " + varsearchid)
print ""
# LOCAL VARIABLES
coordinates = ""
countList = []
countyField = "FIPS2"
countList2 = []
finalList = []
txt_list = ""
txt_list2 = ""
data = ""
# GEOCODERS
geoCodeUrl = r"https://xxxxx/arcgis/rest/services/Geocoding/Composite_Locator/GeocodeServer/findAddressCandidates"
searchAddress = varsearchAddress
searchDistance = varsearchDistance
searchid = varsearchid
# CONVERT MILE TO METERS FOR SPATIAL BUFFER
distanceMeters = int(varsearchDistance) * 1609.34
def singleAdressGeocode(address, geoCodeUrl, outSR = "26917"):
##clean up the address for url encoding
address = address.replace(" ", "+")
address = address.replace(",", "%3B")
#send address to geocode service
lookup = requests.get(geoCodeUrl + "?SingleLine=" + address + "&outSR=" + outSR + "&maxLocations=1&f=pjson")
data = lookup.json()
if data["candidates"]:
##coords = data["candidates"][0]["location"]
##return coords
return data
else:
##no results
return "Address not geocoded: " + address
# DEFINE VARIABLES FOR THE ADDRESS AND X AND Y VALUES
geocodeResult = singleAdressGeocode(searchAddress, geoCodeUrl)
addressResult = geocodeResult["candidates"][0]["address"]
coordinateX = geocodeResult["candidates"][0]["location"]["x"]
coordinateY = geocodeResult["candidates"][0]["location"]["y"]
strcoordinateX = str(coordinateX)
strcoordinateY = str(coordinateY)
arcpy.env.workspace = r"E:/ArcGISProjects/CountySelection/ccccc.sde"
# CREATE THE POINT FROM THE X AND Y
point = arcpy.Point(coordinateX, coordinateY)
ptGeometry = arcpy.PointGeometry(point)
# FEED THE BUFFER ANALYSIS THE POINT GEOMETRY THE DISTANCE PARAMETERS AND WRITE BUFFER TO MEMORY
arcpy.Buffer_analysis(ptGeometry, 'IN_MEMORY/BufferGeom', distanceMeters)
# DEFINE THE COUNTIES FC
arcpy.MakeFeatureLayer_management(r"E:/ArcGISProjects/CountySelection/ccccc.sde/Counties_1_Dissolved", "counties_lyr")
# SELECT FROM BUFFER PUT INTO RESULTS VARIABLE
results = arcpy.SelectLayerByLocation_management('counties_lyr', 'INTERSECT', 'IN_MEMORY/BufferGeom')
# GET THE FIPS CODES FROM THE RESULTS OF THE SELECTION
rows = arcpy.SearchCursor(results,"","","FIPS2")
for row in rows:
neighborVal = str(row.FIPS2)
#print(neighborVal)
countList.append(neighborVal)
txt_list = ','.join(countList)
# COPY THE SELECT RESULTS INTO MEMORY
arcpy.CopyFeatures_management("counties_lyr", "IN_MEMORY/CountiesSelection")
# DISSOLVE THE RESULTS INTO MULTIPART GEOMETRY AND WRITE TO MEMORY
inFeatures = "IN_MEMORY/CountiesSelection"
outFeatures = "IN_MEMORY/Counties_3_dissolved"
arcpy.Dissolve_management (inFeatures, outFeatures)
## GET THE GEOMETRY FROM THE DISSOLVED FC and PASS THAT TO THE INSERT CURSOR BELOW ALONG WITH THE ATTRIBUTE VALUES
geometries = arcpy.CopyFeatures_management("IN_MEMORY/Counties_3_dissolved", arcpy.Geometry())
arcpy.env.overwriteOutput = True
## SET THE TARGET FEATURE CLASS TO ADD THE FINAL MULTI PART GEOMETRY TO
inputFeatureclass = r"E:/ArcGISProjects/CountySelection/ccccc.sde/Poly_WebMercatorAux"
## CREATE A PROPER GID FORMAT FOR GEODATABASE
validGuid = "{{{0}}}".format(str(uuid.UUID(searchid)))
langs.append("{'address':'" + varsearchAddress + "','fids':'" + txt_list + "','id':'" + varsearchid + "'}" )
print "started"
edit = arcpy.da.Editor(r"E:/ArcGISProjects/CountySelection/cccc.sde")
edit.startEditing()
print "edit started"
# Perform edits
## CREATE THE NEW MULTI PART POLYGON IN THE FC
with arcpy.da.InsertCursor(inputFeatureclass, ['SHAPE@', 'ADDRESSgeocode', 'DISTANCEparameter', 'UNIQUEIDparameter', 'COUNTYLIST', 'NWTLID']) as cursor:
cursor.insertRow([geometries[0], searchAddress, searchDistance, searchid, txt_list, validGuid])
## Delete cursor object
del cursor
edit.stopOperation()
print "operation stopped"
# RETURN THE LIST OF FIPS TO THE REST END POINT SENT TO THE 4th PARAMETER OF THE GP TOOL
#msg =("update successful")
#msg =(txt_list)
langs2 = json.dumps(langs, separators=(',', ':'))
msg =(langs)
arcpy.AddMessage(msg)
resultMsg = msg
arcpy.SetParameterAsText(1, resultMsg)
Executing: createNWTLGEometryJSONJays "{"employees":[{"address":"1520 Split Oak Ln, Henrico, Virginia, 23229","distance":"10", "id" : "1a35172e071f4a33b191172a9b4b02ae" },{"address":"1341 Research Center Dr Blacksburg, VA 24060","distance":"9", "id" : "6a35172e071f4a33b191172a9b4b02ae" }]}"
Start Time: Tue Apr 21 15:33:04 2020
Running script createNWTLGEometryJSONJays...
Failed script createNWTLGEometryJSONJays...
Traceback (most recent call last):
File "E:\ArcGISProjects\CountySelection\Python\county.py", line 130, in <module>
cursor.insertRow([geometries[0], searchAddress, searchDistance, searchid, txt_list, validGuid])
RuntimeError: Objects in this class cannot be updated outside an edit session [xxx.DBO.PartPoly_WebMercatorAux]
Failed to execute (createNWTLGEometryJSONJays).
Failed at Tue Apr 21 15:33:06 2020 (Elapsed Time: 1.53 seconds)
... View more
04-21-2020
12:44 PM
|
0
|
2
|
2255
|
|
POST
|
Does this create one feature, in ArcMap is does not..... Are there any examples? I have a Graphics layer with a few graphics in it I want to union this and write a single feature to another graphics layer. var union = geometryEngine.union( graphicsLayer1); graphicsLayer2.addMany(union);
... View more
04-21-2020
06:06 AM
|
0
|
1
|
2037
|
|
POST
|
Can you do a dissolve on a Graphics Layer in ArcGIS JavaScript API 4.x. I see reference to this in 3.x but not 4.x In JavaScript 4.14 I am selecting a specific number of features from a Feature Layer and writing them to a Graphics Layer. I now want to dissolve them to a multi-part polygon so I can update a Feature Class Geometry. Can I do this with the API or do I need to do this with a Python Published GP Tool
... View more
04-20-2020
04:09 PM
|
0
|
3
|
2121
|
|
POST
|
testing this if (testForFIPS) {
// DONT ADD AND REMOVE THIS ONE FROM THE GRAPHICS LAYER
resultsLayer4.remove(selectionGraphic);
} else {
resultsLayer4.add(selectionGraphic);
}
... View more
04-20-2020
07:19 AM
|
0
|
1
|
1881
|
|
POST
|
OK that helped a bit...I can now simply read the Graphic Layer as I click the map and add to it.... I have one twist....as I am adding graphics to the graphics layer every time I click a feature in the map I want to determine if they exist. If they exist then remove them from the Graphics Layer. When this occurs the graphic in the map should disappear. I think I can do this with an IF Else????? Does this make sense.....now just have to dig on how to remove a graphics feature from the Graphics layer. I assume this can be done? var atribArray = [];
viewright.on("click", function (evt) {
// Search for graphics at the clicked location
viewright.hitTest(evt.screenPoint).then(function (response) {
var result = response.results[0];
var FIPS = result.graphic.attributes.FIPS2;
var symbol = {
type: "simple-fill", // autocasts as new SimpleFillSymbol()
color: [51, 51, 204, 0.9],
style: "solid",
outline: { // autocasts as new SimpleLineSymbol()
color: "white",
width: 1
}
};
// Set variable to the newly clicked feature
var selectionGraphic = result.graphic;
selectionGraphic.symbol = symbol;
// Populate Array with each map click
resultsLayer4.graphics.map(function (gra) {
atribArray.push(gra.attributes.FIPS2);
});
// Test to see if this newly clicked feature exists in the Graphics Layer
var testForFIPS = atribArray.includes(FIPS);
if (testForFIPS) { // IF TRUE
// DONT ADD AND REMOVE THIS ONE FROM THE GRAPHICS LAYER
} else {
// ADD THIS ONE BECAUSE IT DOES NOT EXIST
resultsLayer4.add(selectionGraphic);
}
... View more
04-20-2020
07:17 AM
|
0
|
2
|
1881
|
|
POST
|
I am having difficulties reading the graphics layer that I think I am writing to. Just want a for loop of some sort to read the Graphics Layer when the button is clicked to read the values in a particular field for starters.
... View more
04-18-2020
05:54 PM
|
0
|
5
|
1881
|
|
POST
|
I am trying to write to a graphic layer with a user map click. Using a hit test and allowing the user to click counties in the map and writing them to a graphic layer these are then seen displayed in the map as the user clicks on them this seems to work fine viewright.on("click", function (evt) {
viewright.hitTest(evt.screenPoint).then(function (response) {
var result = response.results[0];
var symbol = {
type: "simple-fill", // autocasts as new SimpleFillSymbol()
color: [51, 51, 204, 0.9],
style: "solid",
outline: {
color: "white",
width: 1
}
};
var selectionGraphic = result.graphic;
selectionGraphic.symbol = symbol;
resultsLayer4.add(selectionGraphic);
});
}); I then have a button that reads the Graphics Layer and tries to return the results. var selectButton1 = document.getElementById("select-by-polygon");
selectButton1.addEventListener("click", function () {
viewright.whenLayerView(resultsLayer4).then(function (lyrView) {
lyrView.watch("updating", function (val) {
if (!val) {
lyrView.queryFeatures().then(function (results) {
console.log(results);
});
}
});
});
}); I am unsure if I am tackling this the right way.... I want the user to click the map and select counties and write them to a graphics layer. I then need to read this graphics layer and get the unique id of each feature in the graphics layer. QUESTIONS: Am I correctly writing to the Graphics Layer? Is there a better way to do this? Is there a better way to query the Graphics Layer to get a list of unique IDs from a Field value? Is there a way to click on a County that is already in the Graphics Layer and then remove it and have the blue graphic removed?
... View more
04-18-2020
05:38 PM
|
0
|
6
|
1968
|
|
POST
|
Thank you much for the info Than Aung it is greatly appreciated. New to this implementation from C# and then helps a ton... One thing that I am lacking in is using the tools you described to track my requests....I am learning one day at a time...I thank you greatly for your help and guidance. So if I am reading the change correctly the main failure was the format I was passing my parameter in. I was escaping the string and it was expecting a json string. Used when Escaping the string request.ContentType = "application/x-www-form-urlencoded";// Used when passing a JSON string request.ContentType = "application/json";
... View more
04-17-2020
05:54 AM
|
1
|
0
|
3824
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 09-20-2018 11:09 AM | |
| 1 | 09-10-2018 06:26 AM | |
| 1 | 09-15-2022 11:02 AM | |
| 1 | 05-21-2021 07:35 AM | |
| 1 | 08-09-2022 12:39 PM |
| Online Status |
Offline
|
| Date Last Visited |
09-19-2022
09:23 PM
|