[mapguide-users] IronPython - automate Maestro
Bart Oostdam
bart at giskit.nl
Thu Jul 25 07:45:36 PDT 2024
Hello Jackie,
I am really sorry but things elude me or (and I think that is the case) it just doesn’t work correctly.
I load my code with ‘Run File’ and start with the defined function test() for conveniance.
I made all the variables global just in case.
I am posting my Full test-code:
The screen-shot shows that there is a Pointstyle (console: print statements to console).
1. The “IF’ doesn’t work.
2. I still don’t understand why there is a ‘NoneType’ error. I assume that there is always a ‘default’ vectorScaleRange. The print statements show there is one?
3. The poitnStyle itself seams to be created/defined as well. The print statements show this as well I think.
[cid:image001.png at 01DADEB2.08EBD870]
def test():
"""
------------------------------------------
** Data model: Maestro Layer Defenition **
Derived from XML-Editor using Maestro GUI
------------------------------------------
GUI-topic: Resource Settings
-----------
-- SubLayer --
-- The SubLayer children are:
-- FeatureSource, FeatureClass, Geometry Property, Filter, Hyperlink, Tooltip
AND GUI-topic: Layer Properties Visible in Viewer
-- PropertyMapping (DB-column-names and the selection option for passing to Viewerbeheer)
----------
-- GUI-topic: Layer Styles
-- The SubLayer.VectorScaleRange children are:
-- (Styles:) Points, Lines, Areas Composite(Advanced Stylization)
---------------------
"""
# Call functions:
#----------------
#_ShowResourceID()
#_CpStyle()
#_vectorscale()
_ShowResourceID()
#*********************************************************
def _ShowResourceID():
"""
Get all properties and functions (and children) from SubLayer.VectorScaleRange
"""
# Import into the current namespace
#import inspect
#import pprint
from inspect import * # import inspect library functions to be able to examine classes/objects/functions
from pprint import * # Import pretty print library functions, into the current namespace
# Gobal variable list
global Lijst
global resId
global vectorScaleRange
global ldf
# Create a connection to the Maestro app
conn = app.GetConnection(app.GetConnectionNames()[0])
# Get a specific repository-resource: LayerDefinition-type
##resList = conn.ResourceService.GetRepositoryResources("Library://Waalre/Layers/BOR/Verkeer/", "LayerDefinition")
##resList = conn.ResourceService.GetRepositoryResources("Library://Development/Layers/Verkeersborden/", "LayerDefinition")
ldf = conn.ResourceService.GetResource("Library://Development/Layers/Verkeersborden/Verkeersbord-symbolen.LayerDefinition")
print "LayerDefinition: %s" % ldf
#pprint(dir (ldf)) # Geeft alle properties en functies van 'LayerDefinition'
vectorScaleRange = ldf.SubLayer.GetScaleRangeAt(0)
print "vectorScaleRange: %s" % vectorScaleRange
#pprint(dir (vectorScaleRange)) #Geeft alle properties en functies
#pprint(dir (vectorScaleRange.PointStyle)) #Geeft alle properties en functies
print "Acquired: vectorScaleRange"
#Test if there are PointStyles. If not: create one
if vectorScaleRange.PointStyle is None:
print "PointStyle is apparently 'None'"
print vectorScaleRange
print "Create a new pointStyle"
pointStyle = ldf.CreateDefaultPointStyle()
print pointStyle
#Add the new pointStyle to the vectorScaleRange
vectorScaleRange.PointStyle.AddPointStyle(pointStyle)
#vectorScaleRange.AddPointStyle(pointStyle)
else:
print "There already is a pointStyle"
pointRule = ldf.CreateDefaultPointRule()
print "Created: DefaultPointRule"
pointRule.Filter = "ATTR1 = 'GEWELDIG-Verkeersbord'"
print "Completed: Set PointRule-Filter"
vectorScaleRange.PointStyle.AddRule(pointRule)
print "Added to vectorScaleRange: New DefaultPointRule"
conn.ResourceService.SaveResource(ldf)
print "Saved: Layer definition"
# Get connection (assuming single active connection in Site Explorer)
#conn = app.GetConnection(app.GetConnectionNames()[0])
# Get Layer
#layer = conn.ResourceService.GetResource("Library://Samples/Sheboygan/Layers/Trees.LayerDefinition")
# Get the first scale range
#vectorScaleRange = layer.SubLayer.GetScaleRangeAt(0)
##vectorScaleRange = ldf.SubLayer.GetScaleRangeAt(0)
# The layer definition is also a factory for sub-elements you can add. In this case a new point rule
#pointRule = layer.CreateDefaultPointRule()
##pointRule = ldf.CreateDefaultPointRule()
# Set various properties of this new rule
#pointRule.LegendLabel = "New Point Rule"
##pointRule.Filter = "ATTR1 = 'GEWELDIG-Verkeersbord'"
# Add the new rule
##vectorScaleRange.PointStyle.AddRule(pointRule)
# Save the layer
#conn.ResourceService.SaveResource(layer)
##conn.ResourceService.SaveResource(ldf)
print "Finished: Adding a new PointRule..."
Met vriendelijke groet,
GISkit BV
Bart Oostdam
Van: mapguide-users <mapguide-users-bounces at lists.osgeo.org> Namens Jackie Ng via mapguide-users
Verzonden: donderdag 25 juli 2024 13:46
Aan: MapGuide Users Mail List <mapguide-users at lists.osgeo.org>
CC: Jackie Ng <jumpinjackie at gmail.com>
Onderwerp: Re: [mapguide-users] IronPython - automate Maestro
You really have to be familiar with the XML structure of the resources you are working with. The objects you are interacting with on the console are objects that have near 1:1 structure with their respective XML schema definition.
The bulk of the Maestro API is C# classes auto-generated from the .xsd documents that ship with MapGuide. These .xsd files describe the shape of all the resources (and all the versions of these resources) you can work with in MapGuide. Because these .xsd documents exist in multiple versions, we use C# interfaces to provide commonality across these different auto-generated classes and when working with resources in Maestro API, you're working against these interfaces and never have to deal with the underlying auto-generated classes.
I'm sorry if the API documentation is not that helpful or barebones around these classes/interfaces because practically speaking at the moment it is simpler to just look at the underlying .xsd documents to understand the XML structure of a specific resource type rather than painstakingly repeat all of this documentation in our common wrapping interfaces.
In the case of Layer Definitions, you should refer to the respective LayerDefinition.xsd to understand the structure of a Layer Definition document. These schema files are in the Server/Schema folder of your MapGuide install and are also included in the Schemas directory of your Maestro installation. If you're unable to read/understand these .xsd schema files then I can't really help you there.
Either way, I'll give you a cliff-notes version of the Layer Definition structure:
A Layer Definition has:
- A sub element that indicates if this is a vector, raster or DWF-based drawing layer
- Because we're dealing with a vector layer, it has 1:n vector scale ranges
- Each vector scale range has *zero or one* of:
- A point style
- With 1:n point rules
- A line style
- With 1:n line rules
- An area (polygon) style
- With 1:n area rules
- A composite style (if using advanced stylization)
- With 1:n composite rules
So to then revisit your original problem: Why is there no GetPointStyleAt() function?
Because there is indeed no such function. There's only one point style: The .PointStyle property.
Same thing for line/area/composite styles.
We only provide GetXXXAt() and AddXXX() functions for elements that can exist 1 or more times. Point styles do not qualify. Therefore they only exist as properties to set directly.
Therefore your code should've been this:
if vectorScaleRange.PointStyle is None:
pointStyle = ldf.CreateDefaultPointStyle()
#Add the new pointStyle to the vectorScaleRange
vectorScaleRange.PointStyle = pointStyle
else:
print "There already is a pointStyle"
I would think and hope that as you were typing your original code out in the IronPython console, that the autocomplete did not provide any suggestions for GetPointStyleAt after you hit dot after vectorScaleRange. That is because the autocomplete was telling the truth: There is no such function on the vectorScaleRange object.
- Jackie
You wrote:
Sorry to bother you again.
Trying:
if vectorScaleRange.GetPointStyleAt(0) is None:
pointStyle = ldf.CreateDefaultPointStyle()
#Add the new pointStyle to the vectorScaleRange
vectorScaleRange.PointStyle.AddPointStyle(pointStyle)
else:
print "There already is a pointStyle"
Apparently there is no GetPointStyle() or GetPointStyle
Here is where I cannot seem to grasp the logic of things.
Is there documentation about all getters and setters ?
I searched the API documentation for PointStyle and there is a decscription, however:
I franly do not understand how to use the API documentation and apply it in the context of IronPython.
(There is not much to go on for a beginner on it seems)
Met vriendelijke groet,
GISkit BV
Bart Oostdam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapguide-users/attachments/20240725/8bb38014/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 79234 bytes
Desc: image001.png
URL: <http://lists.osgeo.org/pipermail/mapguide-users/attachments/20240725/8bb38014/attachment.png>
More information about the mapguide-users
mailing list