POST
|
Hi there When programmatically publishing Map Image Services to ArcGIS Enterprise Portal, it is possible to define the service's title (the one which will be displayed in the item’s portal page after publishing) by modifying the .sddraft file. Please find an example below: [...]
layer_sharing_draft = map.getWebLayerSharingDraft(target_server_type, "MAP_IMAGE", service_name)
[...]
# Create Service Definition Draft file
layer_sharing_draft.exportToSDDraft(sddraft_file_path)
# Modify title in sddraft file
xml_sddraft = DOM.parse(sddraft_file_path)
title = xml_sddraft.getElementsByTagName('Title')
title[0].firstChild.data = service_title
# save as new sddraft file
with codecs.open(new_sddraft_path, "w", "utf-8") as f:
xml_sddraft.writexml(writer=f, encoding="utf-8")
f.close()
print(new_sddraft_path)
# stage service
sd_file = arcpy.StageService_server(new_sddraft_path, sd_file_path)
# upload service definition
arcpy.UploadServiceDefinition_server(sd_file, target_url) While this works when creating services, it does not work when overwriting them. (when layer_sharing_draft.overwriteExistingService = True) So when I overwrite an existing service, the title in the variable "service_title" is not shown as title in the service's portal page as I would expect. The question is: Is it possible to edit the .sddraft file in such a way that the service title is changed when overwriting the service? Or is there another way to accomplish this?
... View more
06-03-2020
12:35 AM
|
0
|
0
|
437
|
POST
|
Hi Dan, Thank you for the calcification regarding the alter field tool. I can read the alias as described here, but then i get the alias of the feature class, not the one in the mxd i think. What I am looking for is a way to read the alias saved in the mxd, not in the feature class. But maybe that is not possible with arcpy. Thank you for the help anyways.
... View more
04-22-2020
05:46 AM
|
0
|
0
|
728
|
POST
|
Hi, I noticed that the field alias name, which is shown in the attribute table of ArcMap, does not correspond with the field alias name accessible in arcpy. For example, when "manually" changing the field alias name in the .mxd's attribute table, the alias in arcpy does not change. (accessed alias in arcpy like this) for field in arcpy.ListFields('<Featureclass>'):
print field.aliasName
Is there a way to read the alias name with arcpy (the one created manually, which is saved in the mxd) ? The reason for the question is that I work with a large amount of layers whose field alias names were modified manually in mxds and i need to access those aliases in arcpy. So I am looking for an automated way to read the aliases from the attribute table and then overwrite the actual field aliases with arcpy (using arcpy.management.AlterField). I would highly appreciate any help or hints.
... View more
04-21-2020
06:29 AM
|
0
|
2
|
799
|
POST
|
I sort of found a way to make it work for api 3.x and Web AppBuilder: I added a graphic layer as mask layer, covering the whole map, except the location I want to show. I added the following code to a widget which is opening when the application starts: startup: function startup() {
var webmap = this.map;
// Create Polygon covering the whole world, except an area of interest
var coordinatesMaskLayer = [[-180, 90], [-180, -90], [180, -90], [180, 90], [-180, 90]]; // coordinates of the area which should be masked
var coordinatesAreaOfInterest = [[11, 52], [11, 56], [15, 56], [15, 52], [11, 52]]; // coordinates of the area which should not be masked (must be within coordinatesMaskLayer)
var polygonJson = {
rings: [coordinatesMaskLayer, coordinatesAreaOfInterest],
spatialReference: {wkid: 4326},
};
var polygonMask = new Polygon(polygonJson);
// create graphic from polygon
var graphicPolyMask = new Graphic({
"geometry": polygonMask,
"symbol": {"color": [0, 0, 0, 255], "width": 1, "type": "esriSFS", "style": "esriSFSSolid"}
});
// create a graphic (mask) layer and the polygon to it
var graphicsLayer = new GraphicsLayer();
graphicsLayer.add(graphicPolyMask);
// add the graphic to the map and define opacity
webmap.addLayer(graphicsLayer);
graphicsLayer.setOpacity(0.5);
.......
} It is not the ideal solution, as the graphic layer briefly reloads every time the zoom level is changed. If anyone is aware of a better solution to make this work with Web AppBuilder let me know.
... View more
04-15-2020
07:45 AM
|
1
|
0
|
934
|
POST
|
Hi Egge-Jan, thank you for sharing this example, really nice that we can do that with 4.x. Unfortunately, I must use Web AppBuilder so i cannot use this
... View more
04-14-2020
07:09 AM
|
0
|
0
|
934
|
POST
|
Hi, I have to create a regional data viewer with Web AppBuilder for Developers (2.6). The available layers are on national level, yet the application should only draw the layers in a particular province, while data in the rest of the provinces is masked out. Is it possible to configure an App created with WAB (or the webmap it uses) to only show layers within in a defined extent? Or is there a way to mask / clip layers by extent with JSAPI 3.x? I would be very thankful for suggestions or hints in this matter.
... View more
04-14-2020
02:15 AM
|
0
|
4
|
1046
|
POST
|
Hi, not sure if you are still looking for an answer, you can look here for a code example showing how to set the visibility range with the Python API
... View more
03-05-2020
07:17 AM
|
0
|
0
|
1050
|
POST
|
Thank you very much for your reply. When running .update_definition(), I am encountering the following error message: Field 'currentVersion' cannot be updated. Note sure whether others encounter this issue as well, it works for me when adjusting the code like this: from arcgis.gis import GIS
import getpass
password = getpass.getpass("Enter password: ")
gis = GIS('<PortalUrl>', '<username>', password)
portalItemId = '<PortalItemId>'
from arcgis.features import FeatureLayer
feature_layer_item = gis.content.get(portalItemId)
feature_layer = feature_layer_item.layers[0]
feature_layer
# only name fields which should be updated
service_layer_json = {
"maxScale": 150,
"minScale": 15000
}
result = feature_layer.manager.update_definition(service_layer_json)
result
# {'success': True}
Basically, I am not using the service_layer_json retrieved from the service itself, but created an own service_layer_json object which only has the fields which should be updated.
... View more
03-05-2020
07:01 AM
|
0
|
1
|
1856
|
POST
|
Hi there, I am trying to programmatically change the Visibility Range of layers published to the Enterprise Portal. It is possible to do this manually (as shown below), yet that is not the preferred option as I have to adjust a large amount of layers. When having a look at the Python API I did not find a method which would be able to do that. Any help in this matter would be highly appreciated. I have also been looking through GeoNet and came across similar questions (See https://community.esri.com/thread/241752-setting-visibility-scale-using-the-arcgis-api-for-python, https://community.esri.com/thread/192664-set-visibility-range-andor-add-filter-using-arcgis-python-api), yet I did not find the answer there.
... View more
03-04-2020
04:38 AM
|
0
|
3
|
2044
|
POST
|
Thank you for the answer, just noticed that 2.5 was recently released. I updated to the new version, now it works
... View more
02-11-2020
03:13 AM
|
1
|
0
|
805
|
POST
|
Hi there I would like to access metadata information (such as tags and descriptions) which are stored in a Map with arcpy. According to the documentation, Map class has a metadata attribute, however if I try to access it within ArcGIS Pro I get AttributeError: 'Map' object has no attribute 'metadata'. I tried the following: aprx = arcpy.mp.ArcGISProject("Current")
map = aprx.listMaps()[0]
map.metadata (other attributes of Map can be accessed like this) Am I doing something wrong or is it not possible to access the metadata information like this? Is there currently another way to access metadata information with arcpy or do we have to wait for ArcGIS Pro 2.5 for this functionality? Any help or hints would be very appreciated
... View more
02-06-2020
09:33 AM
|
0
|
2
|
951
|
POST
|
I think i figured it out, The file has to be created in the scratch folder using arcpy.env.scratchWorkspace variable, then it can be downloaded with the returned url as expected import os input_from_client = arcpy.GetParameterAsText(0) file = open(arcpy.env.scratchWorkspace+ "/" + "test.txt","w") file.write(input_from_client) file.close() arcpy.SetParameter(1, file.name)
... View more
12-11-2019
03:00 AM
|
2
|
1
|
2255
|
POST
|
Thank you for the reply. I changed the service the way you suggested and this could remove the text wrapper from the url. Now I am getting this url https://[nameofserver]/gis/rest/directories/arcgisjobs/excelreportservice_gpserver/j08439162107846f99bc04281f6aa0a36/scratch/test.txt I had a look at the server and noticed that the scratch folder is empty. Do I have to change the script so that the textfile is put to the scratch folder?
... View more
12-11-2019
02:10 AM
|
0
|
2
|
2255
|
POST
|
Hi, I want to download a file created by a Geoprocessing Service. For testing, I created a Service from the script below. The script is having a user supplied input of type String and a derived output of type File. import os
input_from_client = arcpy.GetParameterAsText(0)
file = open("testfile.txt","w")
file.write(input_from_client)
file.close()
arcpy.SetParameter(1, file) I thought that I can simply set the created file as output parameter (arcpy.SetParameter) and would then be able to download it with the returned url. Yet, when running the service with the REST interface, it returns an incorrect url (note the <_io.TextIOWrapper name='testfile.txt' mode='w' encoding='cp1252'> part in the end): {
"paramName": "File",
"dataType": "GPDataFile",
"value": {
"url": "https://[nameofserver]/gis/rest/directories/arcgisjobs/excelreportservice_gpserver/j3ddfaa172cc7477288253c965e3c3aba/scratch/<_io.TextIOWrapper name='testfile.txt' mode='w' encoding='cp1252'>"
}
} Any ideas how I can get the correct download url? Would be very thankful for support on this. Regards, Lukas
... View more
12-10-2019
06:27 AM
|
0
|
4
|
2562
|
POST
|
Thank you for clarifying that clipping is not possible on the client. Also thanks for the hint about the Raster Functions. If you allow me a follow-up question: Is it possible to summarize 'statistics' of an image layer within a user supplied geometry (ideally on the client side)? This example brought me on the idea, but maybe it is not possible. Else I believe I can do that with the rest API like this.
... View more
12-04-2019
09:33 AM
|
0
|
0
|
597
|
Title | Kudos | Posted |
---|---|---|
1 | 06-22-2021 07:51 AM | |
1 | 10-19-2020 01:05 AM | |
4 | 02-12-2021 06:47 AM | |
1 | 06-23-2021 06:07 AM | |
1 | 04-15-2020 07:45 AM |
Online Status |
Offline
|
Date Last Visited |
12-12-2023
08:28 AM
|