Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Python library to do client operation on web service respecting Open Geospatial Consortium (OGC) standard

License

Notifications You must be signed in to change notification settings

Gabriel-Desharnais/Mapycli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Mapycli

Python 3 package to do client operations on web service respecting Open Geospatial Consortium (OGC) standard.

How to install

Sometime in the future the package will be on pypi and there will be a .deb or .rpm package, but for now you will need to do

python3 setup.py install

Compatibilitie

This package is develloped and tested on a linux machine it should work on other platform, but there are no guaranties and no support for it. This is a python3 package since python2 end of life is supposed to be on January the first 2020, I will neighter devellope nor support for python2 (python2 needs to die and thus I don't believe in it anymore).

Dependencies

This is a list of package that Mapycli relies on.

  • requests

License

This package is under MIT license, for more information look in LICENSE file.

User manual

This is a complete and exaustiv documentation of how to use the package.

Importing the package

To import the package in your program use:

import mapycli

Session

Although the creation of a session is not mandatory to do requests, it is highly recommanded to use them because it add a lot of functionality and they can make your life easier. A session is an object that will keep in memory some parameters and most importantly the information about ressource available on the server. Session are service specific ('WMS','WFS','WCS','WPS','CWS')

Creating a session

To create a session you should do:

se = mapycli.service.session()

Here service should be replaced by the name of the service e.g. mapycli.WMS.session(). This opperation will create an empty session.

If you want to create a session and to a getcapabilities at the same time:

se = mapycli.service.session(URL,*args,**kargs)

Action on session

Sessions allow 3 type of opperation to control it.

Add

The add opperation enables you to add a source to the session and ask for the getcapabilities of this source. This method returns a getCapabilitiesObject.

re = se.add(URL)
Update

The update opperation enables you to update the informations about the layers. You can do an update on every layers by doing

se.update()

In this case the session will go threw every layer and do a getcapabilities on every different source available. You can also add all arguments allowed by a the getcapabilities requests (including vendor extention) (for more information go see getcapabilities to do an update on somme of the layers.

se.update(url)

The update opperation only add layers and replace the one that already exist with new ones, it will not erase the ones that aren't provided anymore by the server. Therefor, it might not be consistent with the state of the server. If you want full consistency with the server use reset

reset

This opperation will remove the old information about layers in the session. You can reset every layer in the session by doing

se.reset()

If you want to do a reset and then add a specific source you can pass all the getcapabilities parameters. e.g.

se.reset(url)

This opperation will not touch other parameters set in session.

Session variable

If you want to change the default version tag used to communicate with the web service you can change the version variable e.g.

se.version = "1.3.0"

The default values are:

service default version
WMS 1.3.0
WFS 2.0.2
WCS 2.0
WPS 2.0

If you want session requests to be automaticaly decoded with a seledted encoding e.g. utf-8 (so it's faster).

se.autoDecode = "utf-8"

WMS

not available yet

This section will list every WMS supported opperations available. Note that wms session object support all of these opperations e.g. The function call

mapycli.wms.getcapabilities(*args,**kargs)

will translate to

se.getcapabilities(*args,**args)

Note:

It is important to note that since mapycli is using requests under the houd you can always add any parameters to your request (usefull for vendor support) and you force mapycli to not send a default parameter by explicitily setting it to None


GetCapabilities

usage

getCapRes = mapycli.wms.getcapabilities(url,service="WMS",request="GetCapabilities",version="1.3.0",format="application/vnd.ogc.se_xml",**kargs)

every kargs given to getcapabilities will be url encoded and passed directly to the server. The function returns a getCapabilitiesObject object. If the format of the server response is the default one (application/xml) mapycli will parse the response, otherwise the only functionality provided by getCapabilitiesObject will be the

Res = getCapRes.response

This will return you the requests response

If you want to go threw the basic parsing of the xml file you can use getCapDict. This variable is a dictionary that contains lists of every tags with their respective values. Therefore, the content of every tags with a given label at root level are assembled together in a list and placed in the dict with their label as key.

The value stored in the list paired with the key is a tuple of lenght 3. The first element is a dict of tags, if the tag has children, they will be stored in this element. The second element is a dict of the attributes, the key is the name of the attribute and the value is the value of the attribute. The third element of the tuple is the value stored in the tag.

e.g.

dic = getCapRes.getCapDict
# Accessing all 'Service' tags
serv = dic['Service']
# Accessing the first Service tag
s = serv[0]

If you want to go threw a well parsed hierarchy using OGC standard you can use getCapStruct.

e.g.

val = getCapRes.getCapStruct.service.title

val will then have the value of the <Title> tag in <service> tag. Here is a list of all the supported tags and their place in the getCapStruct object.

Link Tag Type Behavior note
service.name <Service><Name> str Expception if no tag. If multiple, first one kept.
service.title <Service><Title> str Exception if no tag. If multiple, first one kept.
service.abstract <Service><Abstract> str If none, name will not be created. If multiple first one kept.
service.onlineResource <Service><OnlineResource> str Exception thrown if no tag. If multiple, first one kept. Attribute xlink:href in OnlineResource
service.keywordList <Service><KeywordList> list of str If none, name will be created with empty list. If multiple, first one kept.
service.contactInformation <Service><ContactInformation> struct If none, name will not be created. If multiple, first one kept.
...contactInformation.contactPersonPrimary <Service><ContactInformation><ContactPersonPrimary> struct If none, name will not be created. If multiple, first one kept.
...contactPersonPrimary.contactPerson <Service><ContactInformation><ContactPersonPrimary><ContactPerson> str If none, name will not be created. If multiple, first one kept.
...contactPersonPrimary.contactOrganization <Service><ContactInformation><ContactPersonPrimary><ContactOrganization> str If none, name will not be created. If multiple, first one kept.
...contactInformation.contactPosition <Service><ContactInformation><ContactPosition> str If none, name will not be created. If multiple, first one kept.
...contactInformation.contactAddress <Service><ContactInformation><ContactAddress> struct If none, name will not be created. If multiple, first one kept.
...contactAddress.addressType <Service><ContactInformation><ContactAddress><AddressType> str If none, name will not be created. If multiple, first one kept.
...contactAddress.address <Service><ContactInformation><ContactAddress><Address> str If none, name will not be created. If multiple, first one kept.
...contactAddress.city <Service><ContactInformation><ContactAddress><City> str If none, name will not be created. If multiple, first one kept.
...contactAddress.stateOrProvince <Service><ContactInformation><ContactAddress><StateOrProvince> str If none, name will not be created. If multiple, first one kept.
...contactAddress.postCode <Service><ContactInformation><ContactAddress><PostCode> str If none, name will not be created. If multiple, first one kept.
...contactAddress.country <Service><ContactInformation><ContactAddress><Country> str If none, name will not be created. If multiple, first one kept.
...contactInformation.contactVoiceTelephone <Service><ContactInformation><ContactVoiceTelephone> str If none, name will not be created. If multiple, first one kept.
...contactInformation.contactElectronicMailAddress <Service><ContactInformation><ContactElectronicMailAddress> str If none, name will not be created. If multiple, first one kept.
service.layerLimit <Service><LayerLimit> int If multiple, first one kept. If none, layerLimit will not be created in service.
service.maxWidth <Service><MaxWidth> int If multiple, first one kept. If none, maxWidth will not be created in service.
service.maxHeight <Service><MaxHeight> int If multiple, first one kept. If none, maxHeight will not be created in service.
service.fees <Service><Fees> str If multiple, first one kept. If none, fees will not be created in service.
service.accessConstraints <Service><AccessConstraints> str If multiple, first one kept. If none, accessConstraints will not be created in service.
capability.exception <Capability><Exception> list of str If multiple, first one kept.
capability.layer <Capability><Layer> list of struct If no tag, variable will not be created.
...layer[n].queryable <Capability><Layer> bool If none, queryable will be set to default (False). Using attribute queryable.
...layer[n].cascaded <Capability><Layer> int If none, cascaded will be set to default (0). Using attribute cascaded.
...layer[n].opaque <Capability><Layer> bool If none, opaque will be set to default (false). Using attribute opaque.
...layer[n].noSubsets <Capability><Layer> bool If none, noSubsets will be set to default (false). Using attribute noSubsets.
...layer[n].fixedWidth <Capability><Layer> int If none, fixedWidth will be set to default (0). Using attribute fixedWidth.
...layer[n].fixedHeight <Capability><Layer> int If none, fixedHeight will be set to default (0). Using attribute fixedHeight.
...layer[n].layer <Capability><Layer><Layer> list of struct If none, layer will not be created in service.
...layer.title <Capability><Layer><Title> str Exception if no tag, if multiple first one kept.
...layer.name <Capability><Layer><Name> str If none, name will not be created, if multiple first one kept.
...layer.abstract <Capability><Layer><Abstract> str If none, name will not be created, if multiple first one kept.
...layer.keywordList <Capability><Layer><KeywordList> list of str If none, name will not be created, if multiple first one kept.
...layer.style <Capability><Layer><Style> list of struct If none, style will be created with an empty list.
...style[n].name <Capability><Layer><Style><Name> str If multiple, first one kept.
...style[n].title <Capability><Layer><Style><Title> str If multiple, first one kept.
...style[n].abstract <Capability><Layer><Style><Abstract> str If multiple, first one kept.
...style[n].legendUrl <Capability><Layer><Style><LegendURL> struct If multiple first one kept. If no tag, name will not be defined.
...legendUrl.width <Capability><Layer><Style><LegendURL> int If multiple first one kept. attribute width
...legendUrl.height <Capability><Layer><Style><LegendURL> int If multiple first one kept. attribute height
...legendUrl.format <Capability><Layer><Style><LegendURL><Format> str If multiple first one kept.
...legendUrl.onlineResource <Capability><Layer><Style><LegendURL><OnlineResource> str If multiple first one kept. use value in xlink:href attribute
...style[n].styleSheetURL <Capability><Layer><Style><StyleSheetURL> struct If multiple, first one kept.
...styleSheetURL.format <Capability><Layer><Style><StyleSheetURL><Format> str If multiple, first one kept.
...styleSheetURL.onlineResource <Capability><Layer><Style><StyleSheetURL><OnlineResource> str If multiple, first one kept. Attribute xlink:href
...layer.crs <Capability><Layer><CRS> list of str If none, name will be created with an empty list.
...layer.exGeographicBoundingBox <Capability><Layer><EX_GeographicBoundingBox> struct If none, name will be created with an empty struct. If multiple, first one kept.
...exGeographicBoundingBox.westBoundLongitude <Capability><Layer><EX_GeographicBoundingBox><westBoundLongitude> float If multiple, first one kept.
...exGeographicBoundingBox.eastBoundLongitude <Capability><Layer><EX_GeographicBoundingBox><eastBoundLongitude> float If multiple, first one kept.
...exGeographicBoundingBox.southBoundLatitude <Capability><Layer><EX_GeographicBoundingBox><southBoundLatitude> float If multiple, first one kept.
...exGeographicBoundingBox.northBoundLatitude <Capability><Layer><EX_GeographicBoundingBox><northBoundLatitude> float If multiple, first one kept.
...layer.boundingBox <Capability><Layer><BoundingBox> list of struct
...boundingBox[n].crs <Capability><Layer><BoundingBox> str Attribute CRS from <BoundingBox>
...boundingBox[n].minx <Capability><Layer><BoundingBox> float Attribute minx from <BoundingBox>
...boundingBox[n].miny <Capability><Layer><BoundingBox> float Attribute miny from <BoundingBox>
...boundingBox[n].maxx <Capability><Layer><BoundingBox> float Attribute maxx from <BoundingBox>
...boundingBox[n].maxy <Capability><Layer><BoundingBox> float Attribute maxy from <BoundingBox>
...boundingBox[n].resx <Capability><Layer><BoundingBox> float Attribute resx from <BoundingBox>
...boundingBox[n].resy <Capability><Layer><BoundingBox> float Attribute resy from <BoundingBox>
...layer[n].attribution <Capability><Layer><Attribution> struct If multiple, first one used.
...attribution.title <Capability><Layer><Attribution><Title> str If multiple, first one used.
...attribution.onlineResource <Capability><Layer><Attribution><OnlineResource> str If multiple, first one used. using attribute xlink:href.
...attribution.logoURL <Capability><Layer><Attribution><LogoURL> struct If multiple, first one used.
...logoURL.width <Capability><Layer><Attribution><LogoURL> int If multiple, first one used. Using attribute width.
...logoURL.height <Capability><Layer><Attribution><LogoURL> int If multiple, first one used. Using attribute height.
...logoURL.format <Capability><Layer><Attribution><LogoURL><Format> str If multiple, first one used.
...logoURL.onlineResource <Capability><Layer><Attribution><LogoURL><OnlineResource> str If multiple, first one used. using attribute xlink:href.
...layer[n].authorityURL <Capability><Layer><AuthorityURL> struct list
...authorityURL[n].name <Capability><Layer><AuthorityURL> str If multiple, first one used. Using attribute name.
...authorityURL[n].onlineResource <Capability><Layer><AuthorityURL><OnlineResource> str If multiple, first one used.
...layer[n].identifier <Capability><Layer><Identifier> struct list
...identifier[n].id <Capability><Layer><Identifier> str Actual value enclosed in Identifier tag
...identifier[n].authority <Capability><Layer><Identifier> str If multiple, first one used. Using attribute authority.
...layer[n].metadataURL <Capability><Layer><MetadataURL> struct list
...metadataURL.type <Capability><Layer><MetadataURL> str If multple, first one used. Using attribute type
...metadataURL.format <Capability><Layer><MetadataURL><Format> str If multple, first one used.
...metadataURL.onlineResource <Capability><Layer><MetadataURL><OnlineResource> str If multple, first one used. Using attribute xlink:href.
...layer[n].dataURL <Capability><Layer><DataURL> struct If multple, first one used.
...dataURL.format <Capability><Layer><DataURL><Format> str If multple, first one used.
...dataURL.onlineResource <Capability><Layer><DataURL><OnlineResource> str If multple, first one used. Using attribute xlink:href.
...layer[n].featureListURL <Capability><Layer><FeatureListURL> struct If multple, first one used.
...featureListURL.format <Capability><Layer><FeatureListURL><Format> str If multple, first one used.
...featureListURL.onlineResource <Capability><Layer><FeatureListURL><OnlineResource> str If multple, first one used. Using attribute xlink:href.
...layer[n].minScaleDenominator <Capability><Layer><MinScaleDenominator> float If multple, first one used.
...layer[n].maxScaleDenominator <Capability><Layer><MaxScaleDenominator> float If multple, first one used.
...layer[n].dimension <Capability><Layer><Dimension> struct list
...dimension[n].name <Capability><Layer><Dimension> str If multiple, first one used. Using name attribute.
...dimension[n].units <Capability><Layer><Dimension> str If multiple, first one used. Using units attribute.
...dimension[n].unitSymbol <Capability><Layer><Dimension> str If multiple, first one used. Using unitSymbol attribute.
...dimension[n].default <Capability><Layer><Dimension> str If multiple, first one used. Using default attribute.
...dimension[n].multipleValues <Capability><Layer><Dimension> str If multiple, first one used. Using multipleValues attribute.
...dimension[n].nearestValue <Capability><Layer><Dimension> str If multiple, first one used. Using nearestValue attribute.
...dimension[n].current <Capability><Layer><Dimension> str If multiple, first one used. Using current attribute.
...dimension[n].extent <Capability><Layer><Dimension> str If multiple, first one used. Using value of Dimension tag.

Inheritance of layers properties is manage with the folowing:

Element Inheritance
Layer No
Name No
Title No
Abstract No
KeywordList No
Style Add
CRS Add
EX_GeographicBoundingBox Replace
BoundingBox Replace
Dimension Replace
Attribution Replace
AuthorityURL Add
Identifier No
MetadataURL No
DataURL No
FeatureListURL No
MinScaleDenominator Replace
MaxScaleDenominator Replace
Layer attributes Replace

If you want to have the list of the layer name you can call the getLayers method.

e.g.

layers = getCapRes.getLayers()

GetMap

GetFeatureInfo

DescribeLayer

GetLegendGraphic

Developement

This package is developed threw documentation driven developement (DDD). If you want to commit a change, the documentation should be the first thing you touch. No pull request without a change in the doc will be merged.

Bibliography

Every document consulted to make this package will be listed here.

About

Python library to do client operation on web service respecting Open Geospatial Consortium (OGC) standard

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages