POST
|
Did you ever find out a solution? I am having the same issue as well. aprx_path = os.environ["APRX_PATH"]
arcpy.AddMessage('APRX_PATH: {}'.format(aprx_path))
if os.path.exists(aprx_path):
arcpy.AddMessage('aprx_path exists')
else:
arcpy.AddMessage('aprx_path DNE')
aprx = arcpy.mp.ArcGISProject(aprx_path) In my case I have verified that the path exists when run from a service, and it is still giving me an OSError, despite working fine when I run manually in Pro (3.1).
... View more
07-18-2023
03:24 PM
|
0
|
0
|
664
|
POST
|
seems like there are still issues with aprx.save() even in 3.1, I can run a geoprocessing script with modifies then saves an .aprx file once after opening ArcGIS Pro, but the same script a second time will give the OSError until I re-open Pro
... View more
07-17-2023
04:15 PM
|
1
|
0
|
2452
|
POST
|
I have a custom JSON template for a web map that I am using in Field Maps. For a layer in the map, I can have conditional visibility in a feature creation/edit form using an Arcade expression for the "visibilityExpression" configuration. It works and the visibility is toggled as expected based on the Arcade Expression: "formInfo": {
"formElements": [
{
"label": "MyAttribute",
"type": "field",
"visibilityExpression": "expr1",
"editable": true,
"fieldName": "MyAttribute",
"inputType": {
"type": "text-box",
"minLength": 0
}
}
],
"expressionInfos": [
{
"expression": "DomainName($feature, \"TYPE\") == \"TYPE1\"",
"name": "expr1",
"returnType": "boolean",
"title": "Attribute Expression"
}
]
}, however, it seems like it doesn't work for the regular popup that comes up when you tap a feature in Field Maps. I have tried applying "visibilityExpression" for "popupInfo", but it doesn't work for me: "popupInfo": {
"popupElements": [
{
"type": "fields"
},
{
"type": "attachments",
"displayType": "auto"
}
],
"fieldInfos": [
{
"fieldName": "MyAttribute",
"format": {
"digitSeparator": false,
"places": 2
},
"isEditable": true,
"label": "MyAttribute",
"tooltip": "",
"visibilityExpression": "expr1"
}
],
"expressionInfos": [
{
"expression": "DomainName($feature, \"TYPE\") == \"TYPE1\"",
"name": "expr1",
"returnType": "boolean",
"title": "Attribute Expression"
}
]
} Is there a way to control the visibility for normal popups in Field Maps?
... View more
03-08-2023
03:11 PM
|
0
|
0
|
365
|
POST
|
I have the following trigger on both update and insert for a table called blocks which stores polygons: AFTER INSERT AS BEGIN
SET NOCOUNT ON
DECLARE int, @ranch_num int, @block_treatment nvarchar(256), @shp geography, @copied_from int, @gdb_from_date datetime2(7)
SELECT * INTO #Temp
FROM inserted
WHILE EXISTS (SELECT * FROM #TEMP) BEGIN
SELECT TOP 1 = OBJECTID, @ranch_num = TRANSACTIONAL_RANCH_NUMBER, @block_treatment = TREATMENT_TYPE, @shp = SHAPE, @copied_from = CAST(COPIED_FROM as int), @gdb_from_date = GDB_FROM_DATE
FROM #Temp
IF @ranch_num IS NOT NULL
BEGIN
IF @block_treatment = 'ORIGINAL'
BEGIN
UPDATE a
SET a.ORIGIN_BLOCK = a.OBJECTID
FROM BLOCKS a
WHERE a.OBJECTID =
END
ELSE
BEGIN
IF (SELECT TOP(1) a.OBJECTID
FROM DEV_ENV.aws.BLOCKS a LEFT JOIN DEV_ENV.aws.TRANSACTIONAL_RANCH_NUMBERS t on a.TRANSACTIONAL_RANCH_NUMBER = t.TRANSACTIONAL_RANCH_NUMBER
WHERE a.SHAPE.STIntersects(
geography::STGeomFromText(
geometry::Point(
geometry::STGeomFromWKB(@shp.STAsBinary(), 4326 ).STCentroid().STX,
geometry::STGeomFromWKB(@shp.STAsBinary(), 4326 ).STCentroid().STY,
4326
).STAsText()
, 4326)
)=1 AND a.TREATMENT_TYPE = 'ORIGINAL' AND t.MEDIA = 1 AND a.TRANSACTIONAL_RANCH_NUMBER = @ranch_num
AND a.GDB_TO_DATE = '9999-12-31 23:59:59.0000000' AND a.ORIGIN_BLOCK IS NOT NULL
ORDER BY a.GDB_FROM_DATE desc
) IS NOT NULL
BEGIN
UPDATE BLOCKS
SET
ORIGIN_BLOCK = (
SELECT TOP(1) a.OBJECTID
FROM DEV_ENV.aws.BLOCKS a LEFT JOIN DEV_ENV.aws.TRANSACTIONAL_RANCH_NUMBERS t on a.TRANSACTIONAL_RANCH_NUMBER = t.TRANSACTIONAL_RANCH_NUMBER
WHERE a.SHAPE.STIntersects(
geography::STGeomFromText(
geometry::Point(
geometry::STGeomFromWKB(@shp.STAsBinary(), 4326 ).STCentroid().STX,
geometry::STGeomFromWKB(@shp.STAsBinary(), 4326 ).STCentroid().STY,
4326
).STAsText()
, 4326)
)=1 AND a.TREATMENT_TYPE = 'ORIGINAL' AND t.MEDIA = 1 AND a.TRANSACTIONAL_RANCH_NUMBER = @ranch_num
AND a.GDB_TO_DATE = '9999-12-31 23:59:59.0000000' AND a.ORIGIN_BLOCK IS NOT NULL
ORDER BY a.GDB_FROM_DATE desc
)
WHERE OBJECTID =
END
END
END
ELSE
BEGIN
UPDATE a
SET a.ORIGIN_BLOCK = null
FROM BLOCKS a
WHERE a.OBJECTID =
END
DELETE FROM #Temp WHERE OBJECTID =
END
END Essentially, what I am trying to do is if a block that is being inserted/updated has a non-original treatment type, I need to find the most recent ORIGINAL block that contains the centroid of the block being inserted/updated. To do this in a trigger, I am first creating a Point geometry to find the centroid, and then converting that geometry to a geography which is used as input for SHAPE.STIntersects. However the inputs to SHAPE.STIntersects is causing an issue when I run geoprocessing scripts that will either call UpdateCursor or InsertCursor on the blocks table. The error I get is: RuntimeError: workspace already in transaction mode If I were to change the input of SHAPE.STIntersects: WHERE a.SHAPE.STIntersects(
geography::STGeomFromText(
geometry::Point(
geometry::STGeomFromWKB(@shp.STAsBinary(), 4326 ).STCentroid().STX,
geometry::STGeomFromWKB(@shp.STAsBinary(), 4326 ).STCentroid().STY,
4326
).STAsText()
, 4326)
)=1 to use the EnvelopCenter of the shape instead of a Point geometry of the centroid: WHERE a.SHAPE.STIntersects(@shp.EnvelopeCenter())=1 I will no longer get the RuntimeError, however it isn't as accurate as using the centroid. I am not so familiar working with shapes in SQL, any ideas what could be wrong with using the centroid Point geometry?
... View more
01-30-2023
04:02 PM
|
0
|
0
|
514
|
POST
|
I am trying to upload a definition for a Web Mapping Application to ArcGIS Online using arcgis.gis. I have a .json file "testWebMappingApplication.json" where I have defined the data for the app. The problem I am running into is that when I check the item in ArcGIS Online Assistant, I see the description JSON but nothing for data. workspace = os.path.dirname(os.path.abspath("__file__"))
input_file_name = workspace + r'\testWebMappingApplication.json'
with open(input_file_name) as input_file:
print('reading {}'.format(input_file_name))
json_input = input_file.read()
default_obj = json.loads(json_input)
ip = {
"title": "WEBAPP_PYTHONTEST",
"type": "Web Mapping Application",
"typeKeywords": [
"JavaScript",
"Map",
"Mapping Site",
"Online Map",
"Ready To Use",
"WAB2D",
"Web AppBuilder",
"Web Map"
]
} I have tried several approaches ways of calling gis.content.add: # gis.content.add(item_properties=ip, folder="DevTest", data=default_obj) # error
# item = gis.content.add(item_properties=ip, folder="DevTest") # works but no data
# item = gis.content.add(item_properties=ip, folder="DevTest", data=json.dumps(default_obj)) # error
item = gis.content.add(item_properties=ip, folder="DevTest", data=input_file_name) # works but no data in ArcGIS Online Assistant The last line doesn't give an error but in ArcGIS Online Assistant I don't see the data JSON, instead there is a link to download the file. Is there a way to set the JSON data for the Web Mapping Application item?
... View more
07-18-2022
10:46 AM
|
0
|
0
|
281
|
POST
|
I haven't noticed much of a difference throughout times of the day. I had a case with ESRI support on this and they were able to reproduce the issue with the same scripts I have provided in this thread, and ended up logging a bug for AGOL proxy services.
... View more
03-15-2022
03:08 PM
|
3
|
4
|
1131
|
POST
|
Hello, I am using Server Object Extensions to add additional processing to ArcGIS REST services on operations like updateFeatures, addFeatures, and query. However when features are added or updated using Field Maps offline areas sync, it does not get processed by the Server Object Interceptors the same way. From some testing, I have found that the offline map sync in Field Maps goes through a different operation 'synchronizeReplica', but there doesn't seem to be information on which features are added or deleted from the sync. Can anyone tell me if it is possible to add processing for offline syncs, or point me towards some documentation on how to do this? Thanks
... View more
03-15-2022
03:04 PM
|
0
|
1
|
582
|
POST
|
I am getting Error 504 on feature layers hosted on AGOL as well. Based on some testing I've done it seems to be a problem with AGOL. I have created a small test that demonstrates the issue: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://unpkg.com/@esri/arcgis-rest-request@3.4.3/dist/umd/request.umd.min.js"></script>
<script src="https://unpkg.com/@esri/arcgis-rest-feature-layer@3.4.3/dist/umd/feature-layer.umd.min.js"></script>
<script src="https://unpkg.com/@esri/arcgis-rest-auth@3.4.3/dist/umd/auth.umd.min.js"></script>
<script>
function getTimeDelta(start, stop){
var timeDelta = parseInt(stop - start);
var days = parseInt(timeDelta / 86400000);
var daysRem = timeDelta - (days * 86400000);
var hours = parseInt(daysRem / 3600000);
var hoursRem = daysRem - (hours * 3600000);
var minutes = parseInt(hoursRem / 60000);
var minutesRem = hoursRem - (minutes * 60000);
var seconds = parseInt(minutesRem / 1000);
var milliseconds = minutesRem - (seconds * 1000);
var results = {
days: days,
hours: hours,
minutes: minutes,
seconds: seconds,
milliseconds: milliseconds
}
return results;
}
const username = ""; // AGOL username
const password = ""; // AGOL password
const portalRestUrl = "https://domain.com/sharing/rest"; // AGOL portal url
const hostedFeatureLayerUrl = "https://utility.arcgis.com/usrsvcs/servers/2d48cb458feb445394d02ddzb7gddb43/rest/services/FOLDER/SERVICE_NAME/FeatureServer/2"; // hosted feature layer url
// create a new portal session
const session = new arcgisRest.UserSession({
username: username,
password: password,
portal: portalRestUrl
});
// list of OBJECTIDs that will be updated
var objectidList = [
12226684,
12226688,
12226685,
12226686,
12227085,
12226687,
12227082,
12226690,
12226689,
12227882,
12227485,
12227482,
12227486,
12227484,
12228282,
12227084,
12227083,
12227483,
12226682,
12226683
];
// get the current time
var startTime = new Date();
objectidList.forEach((oid) => {
// perform an update on each feature from their OBJECTID
arcgisRest.updateFeatures({
url: hostedFeatureLayerUrl,
features: [{"attributes":{"OBJECTID":oid,"FIELD_NAME":16171}}],
authentication: session
}).then(updateResults => {
var currTime = new Date();
console.log('time delta:', getTimeDelta(startTime, currTime));
console.log('results of updateFeatures', updateResults);
console.log(updateResults['updateResults'][0]['objectId']);
console.log('success', updateResults['updateResults'][0]['success']);
}, (reason) => {
var currTime = new Date();
console.log('time delta:', getTimeDelta(startTime, currTime));
console.log('failed', reason);
});
});
</script>
</head>
<body>
</body>
</html> Using ArcGIS REST JS, the above sample takes a hosted feature layer and uses updateFeatures to update a single field for a set of records specified by a list of OBJECTIDs. For every call to updateFeatures, the time it takes for the request to complete is logged in the browser console. From my testing, the code consistently starts giving Error 504s for requests that take longer than 30 seconds. (Despite that the timeout for this service is set to 60 seconds on the server from ArcGIS Server Manager). Individual updateFeatures requests may take longer on some layers compared to others. So for some layers you may have to use more or less records to get requests to start taking longer than the apparent 30 second timeout. If I do the exact same thing except making requests directly to our ArcGIS Server, requests will succeed even if they take longer than 30 seconds to complete, which is what we expect: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://unpkg.com/@esri/arcgis-rest-request@3.4.3/dist/umd/request.umd.min.js"></script>
<script src="https://unpkg.com/@esri/arcgis-rest-feature-layer@3.4.3/dist/umd/feature-layer.umd.min.js"></script>
<script src="https://unpkg.com/@esri/arcgis-rest-auth@3.4.3/dist/umd/auth.umd.min.js"></script>
<script>
function getTimeDelta(start, stop){
var timeDelta = parseInt(stop - start);
var days = parseInt(timeDelta / 86400000);
var daysRem = timeDelta - (days * 86400000);
var hours = parseInt(daysRem / 3600000);
var hoursRem = daysRem - (hours * 3600000);
var minutes = parseInt(hoursRem / 60000);
var minutesRem = hoursRem - (minutes * 60000);
var seconds = parseInt(minutesRem / 1000);
var milliseconds = minutesRem - (seconds * 1000);
var results = {
days: days,
hours: hours,
minutes: minutes,
seconds: seconds,
milliseconds: milliseconds
}
return results;
}
var featureServiceUrl = "https://domain.com/server/rest/services/FOLDER/SERVICE_NAME/FeatureServer/2/updateFeatures";
var generateTokenUrl = "https://domain.com/server/tokens/generateToken";
var username = "";
var password = "";
// call generateToken directly to a ArcGIS Server
async function generateTokenFromServer(url = '', username = '', password = ''){
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
var urlencoded = new URLSearchParams();
urlencoded.append("f", "json");
urlencoded.append("username", username);
urlencoded.append("password", password);
urlencoded.append("client", "requestip");
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: urlencoded,
redirect: 'follow'
};
const response = await fetch(url, requestOptions);
console.log(response);
return response.json();
}
// get a token for calling services
async function getToken(url, username, password){
var generateTokenResponse = await generateTokenFromServer(url, username, password);
return generateTokenResponse['token'];
}
// update a field 'FIELD_NAME' for record with provided objectid
async function updateRecord(url, objectid, fieldValue, token){
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
var urlencoded = new URLSearchParams();
urlencoded.append("f", "json");
urlencoded.append("features", JSON.stringify([
{
"attributes": {
"OBJECTID": objectid,
"FIELD_NAME": fieldValue
}
}
]));
urlencoded.append("token", token);
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: urlencoded,
redirect: 'follow'
};
const response = await fetch(url, requestOptions);
console.log(response);
return response.json();
}
// list of OBJECTIDs that will be updated
var objectidList = [
12226684,
12226688,
12226685,
12226686,
12227085,
12226687,
12227082,
12226690,
12226689,
12227882,
12227485,
12227482,
12227486,
12227484,
12228282,
12227084,
12227083,
12227483,
12226682,
12226683
];
getToken(generateTokenUrl, username, password).then(token => {
// get the current time
var startTime = new Date();
var successCount = 0;
// for each objectid in the list, update it and print how much time has elapsed
objectidList.forEach(oid => {
updateRecord(featureServiceUrl, oid, 16171, token).then(result => {
var currTime = new Date();
console.log('time delta:', getTimeDelta(startTime, currTime));
successCount += 1;
console.log('success count: ', successCount);
console.log('results of updateFeatures', result);
console.log(result['updateResults'][0]['objectId']);
console.log('success', result['updateResults'][0]['success']);
}, reason => {
var currTime = new Date();
console.log('time delta:', getTimeDelta(startTime, currTime));
console.log('failed', reason);
});
});
});
</script>
</head>
<body>
</body>
</html> So it seems like there is a 30 second timeout specific to AGOL hosted feature layers. Even if updateFeatures operations actually succeed and all the records are updated in the underlying feature class, AGOL will still give a 504 for the requests that take longer than 30 seconds, which is frustrating because you don't know whether or not the request actually succeeded. In my examples I did multiple single-edits, but I would guess you would see the same timeout for multiple edits in a single request.
... View more
02-11-2022
03:18 PM
|
0
|
6
|
2526
|
POST
|
We have some geometries that are multipolygons that were accidentally created during mapping. I am trying to clean them up in AGOL with Smart Editor widget but it seems like I am unable to delete vertices for multipolygon shapes, the option to delete is greyed out: I am aware that I can clean them up in ArcMap, but I am wondering if it is possible to do this with web app builder so that users that don't have access to ArcMap can still clean up things like this. Does anyone know if this is possible? Thanks in advanced
... View more
04-12-2021
10:45 AM
|
0
|
1
|
696
|
POST
|
Is there a standard way to add versioning for geoprocessing scripts and tools? Currently, I have a folder for each geoprocessing tool which contains: the python script: this is the script that is run by the tool the toolbox: this contains the settings for parameters README: which has information on how to run the tool These are geoprocessing tools that are published as a service. These aren't really python packages, and the individual scripts aren't really modules since they aren't meant to be imported. A rudimentary way of implementing versioning would be to just manually keep track of them in the README or python script, but I want to know if there are standards or best practices or suggestions for geoprocessing script versions. I am already using github. Ideally I am looking for a solution that allows someone to tell which version of a geoprocessing script is published as a service or deployed in some environment, something that can easily be discerned, like version 2.0.4, as opposed to a commit hash. I am deploying and patching geoprocessing services to multiple machines, so I need a way to tell if a geoprocessing service is up to date.
... View more
03-15-2021
04:18 PM
|
0
|
0
|
396
|
POST
|
I am noticing that CPU and Memory usage can be high when this happens, I am still not 100% sure that is the cause though.
... View more
01-26-2021
04:32 PM
|
0
|
0
|
3352
|
POST
|
I've tried adding: params = urllib.urlencode(params) before the the call to request.post and I still ran into the error
... View more
01-26-2021
02:49 PM
|
0
|
0
|
3355
|
POST
|
If I'm not mistaken, requests will automatically convert the dictionary: https://requests.kennethreitz.org/en/master/user/quickstart/#more-complicated-post-requests I will try using httplib and urllib and see if that helps, but it is still unclear why the script fails sometimes and works other times.
... View more
01-25-2021
09:33 AM
|
0
|
2
|
3366
|
POST
|
I have a published geoprocessing service that is being used by web app builder. This geoprocessing service makes a call to an ArcGIS REST Service. The code first requests for a token so that it can use the REST service to add features to a feature class. There are intermittent issues with the function used to get a token for the REST service where the user can get an error: 'NoneType' object has no attribute 'utf_8_decode' This is the function: # get access token from the arcgis rest server
def get_token(username, password, protocol, arcgis_server_url):
token_url = "{protocol}{host}".format(
protocol=protocol,
host=arcgis_server_url
) + r'/tokens/generateToken'
params = {
'username': username,
'password': password,
"client": "requestip",
'f': 'json'
}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
response = requests.post(token_url, data=params, headers=headers)
if response.status_code == 200:
if 'token' in response.json():
return response.json()['token']
else:
error_msg = 'An error occurred while trying to create an access token. Check login info. Aborting.'
arcpy.AddError(error_msg)
arcpy.SetParameterAsText(13, error_msg)
sys.exit()
else:
error_msg = 'An error occurred while trying to get access token. Aborting.'
arcpy.AddError(error_msg)
arcpy.SetParameterAsText(13, error_msg)
sys.exit() I have the call to this function in a try except block: try:
token = get_token(username, password, protocol, arcgis_server_url)
except Exception as e:
output_msg = str(e) By using debug print statements, I found that it fails on the request post response = requests.post(token_url, data=params, headers=headers) Example parameters: username: username
password: password
protocol = https://
arcgis_server_url = server-name.com/server I have also verified that regardless of whether or not get_token fails, the input parameters are the same. I have found that sometimes when the issue starts occurring, I can temporarily fix the issue by restarting the geoprocessing service. I am using ArcGIS Server: 10.5.1 with Python 2.7.16 Has anyone run into this problem?
... View more
01-22-2021
09:11 AM
|
0
|
5
|
3416
|
Title | Kudos | Posted |
---|---|---|
1 | 07-17-2023 04:15 PM | |
1 | 03-18-2022 03:51 PM | |
3 | 03-15-2022 03:08 PM |
Online Status |
Offline
|
Date Last Visited |
07-26-2023
12:32 AM
|