Select to view content in your preferred language

Creating a mobile map package for an arbitrary area of interest

312
2
08-21-2024 07:05 AM
padmalcom
Frequent Contributor

Hi, we are trying to export a part of a map to a mobile map package. My approach looks like that:

import os
import arcpy
from arcgis.geometry import Polygon

root_dir = "C:\\Users\\mobile\\Alex\\Projects\\ArcGIS\\Mist1"
in_aprx = "Mist1.aprx"
map_name = "Map"

project = arcpy.mp.ArcGISProject(os.path.join(root_dir, in_aprx))
world_map = project.listMaps(map_name)[0]

aoi_def = {
"paths" : [[[-97.06138],[-97.06133,32.836],[-97.06124,32.834],[-97.06127,32.832]],
[[-97.06326,32.759],[-97.06298,32.755]]],
"spatialReference" : {"wkid" : 4326}
}

aoi = Polygon(aoi_def)

arcpy.management.CreateMobileMapPackage(
in_map = world_map,
output_file = r"c:\\Users\\mobile\\MobileMapPackage1.mmpk",
in_locator = None,
area_of_interest = aoi
)

Unfortunately, CreateMobileMapPackage does not accept a polygon as area of interest but requires a full blown feature layer. My question is: How do I programmatically create such a feature layer consisting of 4 pairs or longitude and latitude?

0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

paths" : [[[-97.06138],[-97.06133,32.8 ....

missing something in the first pair ... is it a copy/paste error or did your code throw and error message


... sort of retired...
padmalcom
Frequent Contributor

Thanks @DanPatterson, unfortunately the missing value was not the issue, the error remains the same.

I manually created a feature layer in ArcGIS Pro with one single polygon. When I then call the following function, the export seems to start (at least I don't get an error and the process runs for a while now):

arcpy.management.CreateMobileMapPackage(
  in_map = self.world_map,
  output_file = r"c:\\Users\\mobile\\MobileMapPackage1.mmpk",
  in_locator = None,
  area_of_interest = "NameOfMyManuallyCreatedFeatureLayerWithOnePolygon"
)

 But there MUST be a way to create the area_of_interest programatically, right?

And even when I can't create one, I must be able to edit the existing layer somehow. I tried that using these two functions. First, I get my feature layer using get_layers() which works fine.

  def get_layers(self):
    layers = self.world_map.listLayers()
    fl = None
    for l in layers:
      print(l.name)
      if (l.isFeatureLayer):
        self.fl = l
        print("Found layer, exiting...")
        break
        
  def get_feature_layer(self):
    print("Feature url:", self.fl.URI)
    rfl = FeatureLayer(self.fl.URI)
    #print("RFL features:", rfl.query())

Then I try to convert the Layer instance to a FeatureLayer instance which seems to work fine, but I can not access the features using e.g. featureLayer.query() which fails with an invalid URL. But I don't expect to work with any only map since my map is a local file?

So my goal still is to create a FeatureLayer programatically in python OR edit an existing FeatureLayer. Hope anybody can help me.

 

0 Kudos