本文整理汇总了Python中mapscript.mapObj函数的典型用法代码示例。如果您正苦于以下问题:Python mapObj函数的具体用法?Python mapObj怎么用?Python mapObj使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mapObj函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
def open(self):
self.filename = str(QtGui.QFileDialog.getOpenFileName(None, "Select one file to open", self.firstDir, "MapFile (*.map);;Text (*.txt);;All (*.*)"))
self.map = mapscript.mapObj(self.filename)
try:
self.map = mapscript.mapObj(self.filename)
except Exception:
self.ui.statusbar.showMessage('Error: opening mapfile failed.')
self.ui.statusbar.showMessage('Info: mapfile opened.')
self.updateMapStructure()
示例2: saveGeorefProject
def saveGeorefProject(conf,inputs,outputs):
import mmsession
import mapfile.service as ms
mapfile=conf["main"]["dataPath"]+"/georeferencer_maps/project_"+inputs["map"]["value"]+".map"
m = mapscript.mapObj(mapfile)
conf["senv"]["mmGeoDST"]=m.web.metadata.get("mmGeoDST")
conf["senv"]["mmGeoDSO"]=m.web.metadata.get("mmGeoDSO")
if inputs.has_key("dso") and inputs["dso"]["value"]=="NULL":
inputs["dso"]["value"]=m.getLayer(0).name
conf["senv"]["mmGeoMap"]=inputs["dso"]["value"]
import shutil
ofile=m.getLayer(0).data
shutil.copy2(ofile,conf["main"]["tmpPath"])
conf["senv"]["mmGeoImg"]=ofile.split('/')[len(ofile.split('/'))-1]
mmsession.save(conf)
try:
os.mkdir(conf["main"]["dataPath"]+"/georeferencer_maps/"+inputs["dso"]["value"])
except:
pass
if not(os.path.isfile(conf["main"]["dataPath"]+"/georeferencer_maps/project_"+inputs["dso"]["value"]+".map")) or (inputs.has_key("force") and inputs["force"]["value"]=="true"):
try:
import glob
for name in glob.glob(conf["main"]["dataPath"]+"/georeferencer_maps/"+inputs["map"]["value"]+"/*.csv"):
shutil.copy2(name,conf["main"]["dataPath"]+"/georeferencer_maps/"+inputs["dso"]["value"])
except Exception,e:
print >> sys.stderr,e
pass
m.save(conf["main"]["dataPath"]+"/georeferencer_maps/project_"+inputs["dso"]["value"]+".map")
示例3: testMapWithDefaultMap
def testMapWithDefaultMap(self):
"""ReferenceCountingTestCase.testTestMap: test map constructor with default map file"""
test_map = mapscript.mapObj(TESTMAPFILE)
assert test_map.__class__.__name__ == "mapObj"
assert test_map.thisown == 1
assert test_map.refcount == 1
assert test_map.getLayer(0).refcount == 2
示例4: main
def main(map_file):
map = mapscript.mapObj(map_file)
map.setMetaData("ows_onlineresource", "http://dummy.org/")
ows_req = mapscript.OWSRequest()
ows_req.type = mapscript.MS_GET_REQUEST
ows_req.setParameter("SERVICE", "WMS")
ows_req.setParameter("VERSION", "1.1.0")
ows_req.setParameter("REQUEST", "GetCapabilities")
mapscript.msIO_installStdoutToBuffer()
dispatch_status = map.OWSDispatch(ows_req)
if dispatch_status != mapscript.MS_SUCCESS:
print("An error occurred")
content_type = mapscript.msIO_stripStdoutBufferContentType()
mapscript.msIO_stripStdoutBufferContentHeaders()
result = mapscript.msIO_getStdoutBufferBytes()
# [('Content-Type', 'application/vnd.ogc.wms_xml; charset=UTF-8'), ('Content-Length', '11385')]
response_headers = [('Content-Type', content_type),
('Content-Length', str(len(result)))]
assert int(response_headers[1][1]) > 0
dom = xml.dom.minidom.parseString(result)
print(dom.toprettyxml(indent="", newl=""))
示例5: get_style_from_mapserver
def get_style_from_mapserver(request):
if request.method == 'GET':
layerName = request.GET.get('layer_name')
map = mapscript.mapObj(openthingis.settings.MAPSERVER_MAPFILE)
layer = map.getLayerByName(layerName)
sld = layer.generateSLD()
return HttpResponse(sld, content_type='application/xml')
示例6: __init__
def __init__(self,parent,id,size):
wx.InitAllImageHandlers()
self.size = size
#setup map object
self.map = mapscript.mapObj()
self.map.width = size[0]
self.map.height = size[1]
#self.map.setProjection('proj=latlong,ellps=WGS84')
self.map.setProjection('proj=lcc,ellps=GRS80')
# set the output format
self.map.setOutputFormat(mapscript.outputFormatObj('GD/PNG') )
self.map.interlace = False #PIL can't handle interlaced PNGs
topo=mapscript.layerObj(None)
topo.name="topo"
topo.type=mapscript.MS_LAYER_RASTER
topo.connectiontype=mapscript.MS_RASTER
topo.setProjection('proj=lcc,ellps=GRS80,datum=NAD83')
topo.status = mapscript.MS_ON
topo.tileindex="maps/index.shp"
topo.tileitem="location"
layerNum = self.map.insertLayer(topo)
#fn = self.lookupTopoFilename(0)
#self.loadRaster(fn)
BufferedCanvas.__init__(self,parent,id)
示例7: getMapObj
def getMapObj(self):
mapObj = None
try:
mapObj = mapscript.mapObj(self.mapfile)
except mapscript.MapServerError as err:
self.messageTextEdit.append( str(err) )
return mapObj
示例8: saveGeoreferencedProject
def saveGeoreferencedProject(conf,inputs,outputs):
import mmsession
import mapfile.service as ms
mapfile=inputs["dst"]["value"]+"ds_ows.map"
m = mapscript.mapObj(mapfile)
ms.removeAllLayers(m,inputs["dso"]["value"])
m.web.metadata.set("mmGeoDST",inputs["dst"]["value"])
conf["senv"]["mmGeoDST"]=inputs["dst"]["value"]
m.web.metadata.set("mmGeoDSO",inputs["dso"]["value"])
conf["senv"]["mmGeoDSO"]=inputs["dso"]["value"]
conf["senv"]["mmGeoMap"]=inputs["dso"]["value"]
import shutil
ofile=m.getLayer(0).data
shutil.copy2(ofile,conf["main"]["tmpPath"])
conf["senv"]["mmGeoImg"]=ofile.split('/')[len(ofile.split('/'))-1]
if inputs.keys().count("gcpfile")>0:
m.web.metadata.set("mmGeoGCPFile",inputs["gcpfile"]["value"])
conf["senv"]["mmGeoGCPFile"]=inputs["gcpfile"]["value"]
mmsession.save(conf)
if not(os.path.isfile(conf["main"]["dataPath"]+"/georeferencer_maps/project_"+inputs["dso"]["value"]+".map")):
m.save(conf["main"]["dataPath"]+"/georeferencer_maps/project_"+inputs["dso"]["value"]+".map")
outputs["Result"]["value"]=zoo._("Georeference Project saved")
return zoo.SERVICE_SUCCEEDED
示例9: SecureAccess
def SecureAccess(conf,inputs,outputs):
global myCookies
mapfile=conf["main"]["dataPath"]+"/public_maps/project_"+inputs["server"]["value"]+".map"
try:
myMap=mapscript.mapObj(mapfile)
except:
conf["lenv"]["message"]=zoo._("Unable to find any project with this name!")
return zoo.SERVICE_FAILED
c = auth.getCon(conf)
prefix=auth.getPrefix(conf)
if not(validToken(c,prefix,inputs["token"]["value"])):
conf["lenv"]["message"]=zoo._("Unable to validate your token!")
return zoo.SERVICE_FAILED
if not(validIp(conf,c,prefix,inputs["ip"]["value"],0,[inputs["server"]["value"]])):
conf["lenv"]["message"]=zoo._("You are not allowed to access the ressource using this ip address!")
return zoo.SERVICE_FAILED
q=None
if inputs["Query"]["mimeType"]=="application/json":
import json
q=json.loads(inputs["Query"]["value"])
myAutorizedGroups=myMap.web.metadata.get('mm_access_groups').split(',')
if myAutorizedGroups.count('public')==0 and not(q is None or q["request"].upper()=="GETCAPABILITIES" or q["request"].upper()=="GETLEGENDGRAPHIC") and not(tryIdentifyUser(conf,inputs["user"]["value"],inputs["password"]["value"])):
conf["lenv"]["message"]=zoo._("You are not allowed to access the ressource using this user / password!")
conf["lenv"]["status_code"]="401 Unauthorized"
print >> sys.stderr,conf["lenv"]
return zoo.SERVICE_FAILED
if conf.keys().count("senv")==0:
conf["senv"]={"group": getGroupFromToken(c,prefix,inputs["token"]["value"])}
else:
print >> sys.stderr,conf["senv"]
try:
myCurrentGroups=conf["senv"]["group"].split(',')
except Exception,e:
myCurrentGroups=[]
示例10: update_latest_mapfile
def update_latest_mapfile(self, mapfile, shapePath, geotifRelativePath):
'''
Update the 'latest' mapfile.
Inputs:
mapfile - Full path to the mapfile.
shapePath - Value to attribute to the mapfile's 'shapepath'
variable.
geotifRelativePath - Relative path to the geotiff. This path
is relative to the shapePath argument.
'''
mapObj = mapscript.mapObj(mapfile)
mapObj.shapepath = shapePath
mapWMSMetadata = mapObj.web.metadata
mapWMSMetadata.set('wms_onlineresource',
'http://%s/cgi-bin/mapserv?map=%s&' \
% (self.host.host, mapfile))
layer = mapObj.getLayerByName(self.product.short_name)
layer.data = geotifRelativePath
layerAbstract = '%s product generated for the %s timeslot.' % \
(self.product.short_name,
self.timeslot.strftime('%Y-%m-%d %H:%M'))
layer.metadata.set('wms_abstract', layerAbstract)
mapObj.save(mapfile)
return mapfile
示例11: __init__
def __init__(self, request, **kwargs):
"""
Method to setup map object based on the input parameters. The map
object represents the mapserver mapfile and is used to render
the wms requests.
"""
# Store arguments
self.request = request
self.kwargs = kwargs
# Create mapobject
self.map_object = mapscript.mapObj()
self.register_symbolset()
self.register_layers()
# Set map object properties
self.map_object.setProjection('init=epsg:3857')
self.map_object.setExtent(-180, -90, 180, 90)
self.map_object.setSize(256, 256)
self.map_object.setMetaData('wms_title', self.title)
self.map_object.setMetaData('wms_srs', 'epsg:' + ' epsg:'.join(self.srs))
self.map_object.setMetaData('wms_enable_request',
' '.join(self.enable_requests))
self.map_object.outputformat.transparent = mapscript.MS_ON
# Set legend item size
self.map_object.legend.keysizex = self.legend_size[0]
self.map_object.legend.keysizey = self.legend_size[1]
# Allow debugging
if settings.DEBUG:
self.map_object.debug = mapscript.MS_ON
示例12: _render
def _render(self, inputFile, outputFile):
mapfile = 'MapRenderer/static.map'
# print "Input From: " + inputFile
# print "Output to: " + outputFile
#check output directory exists
if not os.path.exists(self.outputPath):
os.makedirs(self.outputPath)
try:
m = mapscript.mapObj(mapfile)
m.setSize(1542,2523)
#set layer data file
layer = m.getLayerByName("dispersal")
layer.data = inputFile
m.draw().save(outputFile)
except mapscript.MapServerError as e:
print e
pass
#log.critical(e)
except IOError as e:
print e
pass
示例13: mapserver
def mapserver(params,mapfile):
""" Function implementing mapserver functionality.
params: dictionary of query string of a mapserver GET request
mapfile: path to mapfile
returns: tuple with content type and response body
"""
helper.dbg("creating map for: " + mapfile)
request = mapscript.OWSRequest()
#request.loadParams()
for k in params:
#helper.dbg( "%s : %s" % (k,params[k]))
request.setParameter(k,params[k])
# change the style INSPIRE:DEFAULT back to an empty string otherwise Mapserver will complain
styles = request.getValueByName('STYLES')
if (styles is not None and styles.count(default_style) > 0):
styles = styles.replace(default_style, "")
request.setParameter("STYLES", styles)
style = request.getValueByName('STYLE')
if style == default_style:
request.setParameter("STYLE", "")
map = mapscript.mapObj( mapfile )
mapscript.msIO_installStdoutToBuffer()
map.OWSDispatch( request )
content_type = mapscript.msIO_stripStdoutBufferContentType()
content = mapscript.msIO_getStdoutBufferBytes()
operation = request.getValueByName('REQUEST')
version = request.getValueByName('VERSION')
if (version == '1.3.0' or version is None) and operation.upper() == 'GETCAPABILITIES':
content = altercapabilities(content, namespace, prefix, schemaLocation, language)
#response = 'Content-type: %s\n%s' % (content_type,content)
return [content_type, content]
示例14: bug_673
def bug_673():
if string.find(mapscript.msGetVersion(),'SUPPORTS=PROJ') == -1:
return 'skip'
map = mapscript.mapObj('../misc/ogr_direct.map')
map.setProjection('+proj=utm +zone=11 +datum=WGS84')
layer = map.getLayer(0)
# Draw map without reprojection.
layer.setProjection('+proj=utm +zone=11 +datum=WGS84')
img1 = map.draw()
# Draw map with reprojection
map.setProjection('+proj=latlong +datum=WGS84')
map.setExtent(-117.25,43.02,-117.21,43.05)
img2 = map.draw()
try:
os.mkdir('result')
except:
pass
img2.save( 'result/bug673.png' )
# Verify we got the image we expected ... at least hopefully we didn't
# get all white which would indicate the bug is back.
return pmstestlib.compare_and_report( 'bug673.png' )
示例15: wms
def wms(request):
import mapscript
image = None
for field in ['IMAGE', 'COVERAGE', 'image', 'coverage', 'id', 'ID']:
if field in request.GET: image = request.GET[field]
try:
image = int(image)
obj = Map.objects.get(pk=image)
filename = obj.warped
except:
filename = "%s" % image
filename = "%s/%s" % (settings.MAP_PATH, os.path.basename(filename))
ows = mapscript.OWSRequest()
for k, v in request.GET.items():
if k.lower() in ['image', 'coverage']: continue
ows.setParameter(k, v)
ows.setParameter("LAYERS", "image")
ows.setParameter("COVERAGE", "image")
map = mapscript.mapObj('%s/wms.map' % settings.BASE_PATH)
raster = mapscript.layerObj(map)
raster.name = 'image'
raster.type = mapscript.MS_LAYER_RASTER
raster.data = filename
raster.status = mapscript.MS_DEFAULT
raster.setProjection( "+init=epsg:4326" )
raster.dump = mapscript.MS_TRUE
raster.metadata.set("wcs_formats", "GEOTIFF JPEG2000")
mapscript.msIO_installStdoutToBuffer()
contents = map.OWSDispatch(ows)
content_type = mapscript.msIO_stripStdoutBufferContentType()
content = mapscript.msIO_getStdoutBufferBytes()
return HttpResponse(content, content_type = content_type)