POST
|
I'm working with Python to load a web map into a map frame on a layout. However, what I'd now like to do is add a Grid (or Graticule, or Ticks) so that we can see coordinates - preferably along the top and left sides, with the lines either being not visible or transparent. Currently I'm using the below code: #create an aprx using a webmap json and a layout template, and a map based on it
result = arcpy.mp.ConvertWebMapToArcGISProject(data, templateFull)
aprx = result.ArcGISProject
m = aprx.listMaps()[0]
#find our layout and the map frame within
lyt = aprx.listLayouts()[0]
mf = lyt.listElements("mapframe_element", "WEBMAP_MAP_FRAME")[0]
#assign the map to our map frame
mf.map = m
#just gets some extents and sets the map frame and map camera
myExtent = arcpy.Extent(pointMin.centroid.X, pointMax.centroid.Y, pointMax.centroid.X, pointMin.centroid.Y)
mf.camera.setExtent(myExtent)
mf.camera.scale = mf.camera.scale * 1.1
m.defaultCamera = mf.camera Just about everything I can find so far indicates that, if you want to do it programatically, you have to create a Grid "layer" - basically a layer of square polygons, but I'm sure you must be able to expose the Map Frame's Grid settings. You can add a Grid in the Layout editor but, as this is generated on-the-fly as it were from a web map, that option is greyed out.
... View more
09-06-2023
11:20 PM
|
0
|
1
|
686
|
POST
|
I'm currently adjusting an Imagery Layer's mosaicRule using a widget. I can set it, but I don't seem to be able to refresh the Imagery Layer so it shows what I want it to show - it just continues showing the same image with no change. Code is: let mosaicRule = new MosaicRule({
where: "acquisitiondate >= '2023-06-18' AND acquisitiondate <= '2023-06-22'"
});
jimuMapView.view.map.findLayerById("Sentinel2_2968").mosaicRule = mosaicRule;
console.log(jimuMapView.view.map.findLayerById("Sentinel2_2968").mosaicRule)
jimuMapView.view.map.findLayerById("Sentinel2_2968").refresh(); Something I CAN do is apply this same mosaicRule to a new layer and add that to the map - however I'd really not like to have to go through the map and find the layer, destroy it, and add a new one every time the user wants to make this change: let mosaicRule = new MosaicRule({
where: "acquisitiondate >= '2023-06-18' AND acquisitiondate <= '2023-06-22'"
});
const layer = new ImageryLayer ({
url: "https://myserver.com/portal/sharing/servers/itemid/rest/services/Sentinel2/ImageServer",
format: "jpgpng"
})
layer.mosaicRule = mosaicRule
jimuMapView.view.map.add(layer) Any idea how I can refresh the existing layer rather than having to create it all over again every time we change anything?
... View more
07-24-2023
06:51 PM
|
0
|
0
|
440
|
POST
|
I'm creating a new project in ArcGIS Experience Builder and one of the main things it needs is Sentinel-2 integration. We need not only the "latest" imagery (or whatever is loaded by default), but also the ability to manually select the date that is shown. Currently, I've written a widget that I'm just using for debugging purposes. The webmap that is shown has a Sentinel-2 image service (from ESRI, using my ArcGIS Online credentials). The Sentinel-2 view itself can be found at https://www.arcgis.com/home/item.html?id=fd61b9e0c69c4e14bebd50a9a968348c However, ESRI has yet to implement support for image services in Experience Builder. Normally a layer like that would be registered as "time-enabled" and be able to have a timeline widget associated with it, sorting everything out without any code whatsoever. Unfortunately, we don't have that luxury, and I'm trying to do it in code. This is my widget's runtime code so far, trying to pick up the data. It should be noted that field 9 is the "acquisitionDate" field, which is the one I would want to alter: import { React, AllWidgetProps } from 'jimu-core'
import { JimuMapViewComponent, JimuMapView } from 'jimu-arcgis'
const { useState } = React
const Widget = (props: AllWidgetProps<any>) => {
const [jimuMapView, setJimuMapView] = useState<JimuMapView>()
const activeViewChangeHandler = (jmv: JimuMapView) => {
if (jmv) {
setJimuMapView(jmv)
}
}
const formSubmit = (evt) => {
evt.preventDefault()
console.log('Some stuff here')
console.log(jimuMapView.jimuLayerViews)
console.log(jimuMapView.view.map.findLayerById("Sentinel2_2968").visible)
console.log(jimuMapView.view.map.findLayerById("Sentinel2_2968"))
console.log(jimuMapView.view.map.findLayerById("Sentinel2_2968").fields[9])
jimuMapView.view.map.findLayerById("Sentinel2_2968").visible = true
}
return (
<div className="widget-starter jimu-widget">
{
props.useMapWidgetIds &&
props.useMapWidgetIds.length === 1 && (
<JimuMapViewComponent
useMapWidgetId={props.useMapWidgetIds?.[0]}
onActiveViewChange={activeViewChangeHandler}
/>
)
}
<form onSubmit={formSubmit}>
<div>
<button>Debug</button>
</div>
</form>
</div>
)
}
export default Widget
... View more
07-23-2023
10:56 PM
|
1
|
2
|
638
|
IDEA
|
We'd need this too, for accessing the Sentinel-2 service. I'm currently trying (and failing) to hack away at the service through widgets and console logging to get to the acquisition date, so a dedicated way of using a timeline would be great. Have upvoted the idea.
... View more
07-23-2023
06:25 PM
|
0
|
0
|
1354
|
POST
|
Hi Archit Hmm... an odd one. I checked validation in the Portal Admin Directory, and in the Server Manager. All were fine. I then decided to try to create a new Feature Layer, rather than bring in a zipped shapefile (which just published the shapefile before - it didn't create a hosted Feature Layer). However, even though I've done this quite a lot in ArcGIS Online, I couldn't find any option to create a new feature layer - or indeed anything like it! Instead, I just get the drag/drop option, URL, Application, and Data Store: Also, when I did add a zipped shapefile, it did not come up with an option to host it as a hosted feature layer/service: In terms of logs, I tried looking through the period when I added the above file and couldn't see anything.
... View more
07-23-2023
06:05 PM
|
0
|
0
|
1057
|
POST
|
Thanks Miguel. I've already tried restarting the datastore, with no avail, and looked through that topic (nothing in there that looks relevant to me). My describedatastore output is:
... View more
07-23-2023
05:11 PM
|
0
|
0
|
1058
|
POST
|
I've got a single machine that I'm using as an ArcGIS Enterprise server (with Portal) and have a data store on the same machine. I've just installed the data store (using the standalone installer, 10.9.1 - all my server elements are 10.9.1). In ArcGIS Pro, whenever I try to share a web layer and copy all of the contents to the server (so it can be used as a repository for data eg contours), the analyze/publish options are greyed out for anything other than a map image layer (which I don't want, I need it to be a feature layer). Also, in Portal, if I try to copy the zipped shapefile over, it simply copies the shapefile rather than giving me the option to create a HFS. Looking into the logs, I can see this in one of the server logs: <Msg time="2023-07-14T04:04:26,131" type="WARNING" code="110801" source="Data Store" process="13184" thread="1" methodName="" machine="MYMACHINE" user="" elapsed="" requestID="">Failed to start tile cache data store. Read from ArcGIS Data Store configuration store failed.</Msg> <Msg time="2023-07-14T04:04:26,135" type="SEVERE" code="110306" source="Data Store" process="13184" thread="1" methodName="" machine="MYMACHINE" user="" elapsed="" requestID="">Attempt to start 'tile cache' data store failed. Read from ArcGIS Data Store configuration store failed.</Msg> Anyone got any ideas? Thanks.
... View more
07-13-2023
09:59 PM
|
0
|
5
|
1437
|
POST
|
I'm trying to create a web tool which will access a layout. The layout contains a web map which already displays some layers, and I'd like to set the definition query on them to only show certain features. However, for some reason this isn't working. I've managed it in other scenarios, such as loading up a web map with a blank mapframe and adding the layers to that, but I'd like it to use a web map this time in order to make editing it easier. In any case, for some reason it seems to ignore the definition query and return the same number of features, as if the definition query isn't active (I have checked it, it is active, the layer supports definition queries and this is the only definition query on it). Code snippet below: lyt = aprx.listLayouts()[0]
mf = lyt.listElements("mapframe_element", "WEBMAP_MAP_FRAME")[0]
mfm = mf.map
myLayer = mfm.listLayers("UseThisLayer")[0]
myLayer.definitionQuery = "ThisId = 'abc'"
with arcpy.da.SearchCursor(myLayer, "Shape@") as cursor:
for row in cursor:
if row[0]:
arcpy.AddMessage(row[0]) As I say, I can put anything into the definition query and it still returns the same amount of values, as if it's not there. And I can interrogate the layer's definition query, see that it is active, supported and the only one there. I do have another way round this (which would be defining the layers outside of the layout, then adding them to the layout's mapframe) but as I say, I'd really like not to have to do this if I can avoid it. Edit - should point out that this is using ArcGIS Pro, but the layout (and web map and layers) are on my Portal. Eventually this will become a web tool. Another edit - using the below: arcpy.AddMessage(myLayer.listDefinitionQueries()) Gives us: [{'name': 'Query 1', 'sql': "ThisId = 'abc'", 'isActive': True}]
... View more
02-06-2023
08:36 PM
|
0
|
1
|
711
|
POST
|
Huh, go figure. It may have been running all along, I'm unsure. In my latest code, I made a couple of little tweaks to my requestparams. It is instead: var requestParams = {
method: "post",
query: {
f: 'json',
username: 'MyUsername',
password: 'MyPassword',
client: 'requestip'
}
}; And added the token to my url, at the end. In any case, I'm still getting the signin screen, which I believe is because I'm calling the job wrong (at the moment I'm just using a window.open to call the url), but the job still calls and executes. I just assumed it wasn't because of the login screen. Now to find a better way to call the job... (eventually, because now other tasks have popped up)
... View more
10-17-2022
09:12 PM
|
0
|
0
|
323
|
POST
|
Sure. Sorry I've only just gotten round to this now, been in the field a bit. See below for the edited version: var tokenUrl = "https://myserver.com/portal/sharing/rest/generateToken";
var requestParams = {
method: "post",
query: {
f: 'json',
username: 'MyUsername',
password: 'MyPassword',
referer: window.location.origin
}
};
var myRequest = esriRequest(tokenUrl, requestParams);
myRequest.then(function(response){
var token = response.data.token;
esriId.registerToken({
server: "https://myserver.com/portal/sharing/rest",
token: token
});
initMap();
}); As I say, I have a tool which I can call using the following: https://myserver.com/server/rest/services/MyPrintLayouts/ScriptX01_AGP2_9/GPServer/ScriptX01/submitJob?&MyId=%7B<MyIdAsGUID>%7D&FileDestination=C%3A%5Ctemp%5C%7B<MyFilename>%7D.pdf&env%3AoutSR=&env%3AprocessSR=&returnZ=false&returnM=false&returnTrueCurves=false&context=&f=html If I'm logged into the server already, then it works fine. If I'm not however, I get presented with a login screen. I'd like to be able to use the token to access it, which doesn't seem to work if I include it in the URL (which I assume I'm doing wrong).
... View more
10-17-2022
08:37 PM
|
0
|
0
|
324
|
POST
|
I have a scripting tool on my Portal which works fine if the user is signed in. However, if the user is not signed in, the scripting tool obviously doesn't work. I also have a token, which has been generated earlier (though not much earlier - the token is still current). Is it possible to use this token to run my scripting tool, and if so, how should it be passed into the URL? This is a very basic version of how it works: window.open("https://myserver.com/server/rest/services/MyPrintLayouts/ScriptX01_AGP2_9/GPServer/ScriptX01/submitJob?Id=" + vId + "&FileDestination=" + vDestination + "&env%3AoutSR=&env%3AprocessSR=&returnZ=false&returnM=false&returnTrueCurves=false&context=&f=html", '_blank'); I've tried adding a &token=" + token Extra token parameter in there but that's not working. Each time it gets called, if the user isn't signed in, it will go to the sign in screen.
... View more
10-06-2022
10:08 PM
|
0
|
3
|
392
|
POST
|
I'm trying to set up and use a folder data store, so that I can access a layout.pagx file stored on my server in code (specifically, in ConvertWebMapToArcGISProject). ArcPy code should be something like this: templatePath = "\\myserver.com\server\LayoutStorage"
templateFile = "layout.pagx"
templateFull = os.path.join(templatePath, templateFile)
result = arcpy.mp.ConvertWebMapToArcGISProject(data, templateFull) Where LayoutStorage is the name of my folder data store, and layout.pagx is my layout file (see convertwebmaptoarcgisproject and data-store-items) Now, I don't think I've set this up correctly. The folder I've set up to be my data store is located on the server, simply at C:\Datastore_Layouts. In here there is the layout.pagx file (so C:\Datastore_Layouts\layout.pagx). The folder is shared with the ArcGIS user accounts. The data store item, in my Portal, has been set to address the \\localhost\Datastore_Layouts folder. This has been validated. It can be accessed by my https://myserver.com/server server (with a green tick next to it for status). However, I keep getting: RuntimeError: Missing or invalid layout template file. I must say though that, for testing purposes, I am doing this on my local install of ArcGIS Pro (and not on the server machine). Any help would be greatly appreciated - this is (hopefully) the last thing I need to get on this. Either that, or if there is a way to address a layout.pagx file from the existing Portal?
... View more
10-03-2022
10:22 PM
|
0
|
0
|
748
|
POST
|
That's definitely some useful code. However, my code *was* working, but my code hadn't been put together well. I was trying to address a layer which didn't exist because I hadn't given it a title in the json I'm putting the webmap together with.
... View more
10-03-2022
08:56 PM
|
0
|
0
|
738
|
POST
|
I'm trying to narrow down a layer using the lyr.definitionQuery = ... method, as below: result = arcpy.mp.ConvertWebMapToArcGISProject(data, templateFull)
aprx = result.ArcGISProject
#get the map, layer, apply the definition query
m = aprx.listMaps()[0]
lyr = m.listLayers("MyLayer")[0]
lyr.definitionQuery = "GUIDId = '" + RequestedGUIDId + "'" Now, this works fine if I do it using my current project on my computer, with everything loaded locally (so I don't have to bother with the ConvertWebMapToArcGISProject). However, we're trying to implement this online, so we have to get a json containing the layers we need and convert it to a project in the code. Now, for some reason, the lyr.definitionQuery line is not working - or more rather, it's having no effect. No matter what, it always returns the same number of features, which is odd (as my layer contains about 20,000 features - yet it always returns 151, even if I enter different values, or even values that don't exist!). The layer does support definition queries (I've tested that), and it definitely recalls the definition query (I've given it a delay after the definition query is set, and checked it by outputting). It's getting set, but for some reason the layer isn't paying any attention to it.
... View more
09-29-2022
11:04 PM
|
0
|
2
|
781
|
POST
|
I've got a layout file that I've copied to my Portal. The layout refers to a webmap (which contains a few layers). My intention is to print the layout, zoomed to a certain extent (which I'd pass through to it), and only showing certain features (which, again, I can pass to it, or provide in a definition query). How would I accomplish this? I managed it using a local project, but now I'm trying to do it via Portal and have to use the arcgis.gis module. I've got code that will log in to the Portal and get the required extent, so just need to know how to interact with the layout. My code, so far, is below: import arcpy, os, sys
from arcgis.mapping import WebMap
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
#get variables
RequestedId = arcpy.GetParameterAsText(0)
cUN = arcpy.GetParameterAsText(1)
cPW = arcpy.GetParameterAsText(2)
#connect
gis = GIS(r"https://mydomain/portal", cUN, cPW)
#try and load the webmap
wm_item = gis.content.get("WebMapId")
wm = WebMap(wm_item)
#try to access the layer
for lyr in wm.layers:
if lyr.title == "MyLayer":
#convert it into a feature layer for local use
flayer = FeatureLayer(lyr.url)
###some handy old code, no longer used
###for f in flayer.properties.fields:
### arcpy.AddMessage(f['name'])
#grab the extent
MyExtent = flayer.query(where="Id='" + RequestedId + "'", return_extent_only=True)
#now we're going to need our layout
lyt_item = gis.content.get("MyLayoutId")
arcpy.AddMessage(lyt_item) For reference, this was my original code, which worked fine using a local project. Basically, I'd like to replicate this: import arcpy
#select our current map, and then the layer we want, and grab our Id from parameters
aprx = arcpy.mp.ArcGISProject("CURRENT")
RequestedId = arcpy.GetParameterAsText(0)
m = aprx.listMaps("MyWebMap")[0]
lyr = m.listLayers("MyLayer")[0]
#set our definition query
lyr.definitionQuery = "Id = '" + RequestedId + "'"
#define our extents
extents = []
#loop through and add our shape extent
with arcpy.da.SearchCursor(lyr,'SHAPE@') as cursor:
for row in cursor:
if row[0]:
extents.append(row[0].extent)
#get our actual extent
eXMin = min([ext.XMin for ext in extents])
eXMax = max([ext.XMax for ext in extents])
eYMin = min([ext.YMin for ext in extents])
eYMax = max([ext.YMax for ext in extents])
#now go into the layout
lyt = aprx.listLayouts("Layout")[0]
mf = lyt.listElements("mapframe_element", "WEBMAP_MAP_FRAME")[0]
mf.map = m
myExtent = arcpy.Extent(eXMin, eYMax, eXMax, eYMin, 0, 0)
mf.camera.setExtent(myExtent)
mf.camera.scale = mf.camera.scale * 1.1
m.defaultCamera = mf.camera
lyt.exportToPDF("C:\\temp\\mylayout.pdf") I've seen some things saying that you need to know where in the DataStore the layout is saved, but I can't find any way to find this out.
... View more
09-27-2022
11:27 PM
|
0
|
0
|
420
|
Title | Kudos | Posted |
---|---|---|
1 | 07-23-2023 10:56 PM | |
1 | 07-25-2022 10:50 PM | |
1 | 07-27-2021 08:16 PM | |
1 | 07-27-2021 10:44 PM |
Online Status |
Offline
|
Date Last Visited |
a week ago
|