Example #1
0
    def get_layer_points_wfs(self, layer, bbox, max_features):

        # Get points in bbox by creating/dispatching an WFS GetFeature
        # internally. This is a nice abstraction from various source types like
        # PostGIS, Shape etc.
        wfs_req = mapscript.OWSRequest()
        wfs_req.setParameter("SERVICE", "WFS")
        wfs_req.setParameter("VERSION", "1.1.0")
        wfs_req.setParameter("REQUEST", "GetFeature")
        wfs_req.setParameter("TYPENAME", layer)
        wfs_req.setParameter("BBOX", bbox)
        wfs_req.setParameter("VERSION", "1.1.0")
        #    wfs_req.setParameter( 'SRSNAME', "EPSG:4326")  ?????

        # TODO: reproject response points

        mapscript.msIO_installStdoutToBuffer()

        self.map.OWSDispatch(wfs_req)
        #    print 'bbox=' + wms_req.getValueByName('BBOX')
        mapscript.msIO_stripStdoutBufferContentType()
        content = mapscript.msIO_getStdoutBufferString()

        # Parse WFS result into array of Point (slooow, TODO optimize)
        parser = WFSParser(mapscript.msGetVersionInt() >= 50600, max_features)

        return parser.parse(content)
    def render(self, extent, size):
        message = ""
        mapObj = self.getMapObj()

        mapObj.setConfigOption("MS_ERRORFILE", "stdout")
        mapObj.debug = 5

        mapObj.setExtent(extent.xMinimum(), extent.yMinimum(), extent.xMaximum(), extent.yMaximum())
        mapObj.setSize(int(size[0]), int(size[1]))
        message += "Rendering %s" % extent.toString()

        data = ""
        try:
            mapscript.msIO_installStdoutToBuffer()
            mapImage = mapObj.draw()  # = mapscript.imageObj(int(size[0]), int(size[1]), self.mime_type)
            data = mapImage.getBytes()
            message += "Image size: %s" % str(len(data))

            out = mapscript.msIO_getStdoutBufferString()
            mapscript.msIO_resetHandlers()
            message += out
        except mapscript.MapServerError as err:
            message += str(err)

        return data, message
  def render(self, extent, size):
    message = ""
    mapObj = self.getMapObj()

    mapObj.setConfigOption("MS_ERRORFILE", "stdout")
    mapObj.debug = 5

    mapObj.setExtent(extent.xMinimum(), extent.yMinimum(), extent.xMaximum(), extent.yMaximum())
    mapObj.setSize(int(size[0]), int(size[1]))
    message += "Rendering %s" % extent.toString()

    data = ''
    try:
      mapscript.msIO_installStdoutToBuffer()
      mapImage = mapObj.draw() #= mapscript.imageObj(int(size[0]), int(size[1]), self.mime_type)
      data = mapImage.getBytes()
      message += "Image size: %s" % str(len(data))

      out = mapscript.msIO_getStdoutBufferString()
      mapscript.msIO_resetHandlers()
      message += out
    except mapscript.MapServerError as err:
      message += str(err)

    return data, message
Example #4
0
    def ows_req(self):
        # http://mapserver.org/ogc/mapscript.html#python-examples
        ows_req = mapscript.OWSRequest()
        ows_req.loadParams()
        req_str = ows_req.getValueByName("REQUEST")
        styles = ows_req.getValueByName("STYLES")

        do_heatmap = styles and styles.startswith("heat")

        # Filter out "graphic" WMS requests
        if req_str == "GetMap" and do_heatmap:
            self.wms_getheatmap_req(ows_req)
            return
        elif req_str == "GetLegendGraphic":
            # GetLegendGraphic may have a optional STYLE parameter
            # if this indicates a heatmap style defer to our own implementation
            # to return heatmap gradient image as style for now.
            style = ows_req.getValueByName("STYLE")
            if style and style.startswith("heat"):
                self.wms_getheatmaplegend_req(ows_req)
                return

        # All other OWS (WFS/WMS-non-graphic) are XML-based
        # and can be dispatched/returned directly
        ows_req.setParameter("STYLES", "")
        mapscript.msIO_installStdoutToBuffer()
        self.map.OWSDispatch(ows_req)

        if req_str == "GetMap":
            content = mapscript.msIO_getStdoutBufferBytes()
        else:
            content_type = mapscript.msIO_stripStdoutBufferContentType()
            content = mapscript.msIO_getStdoutBufferString()

            if (
                content_type == "vnd.ogc.se_xml"
                or content_type == "application/vnd.ogc.wms_xml"
                or content_type == "application/vnd.ogc.gml"
            ):
                content_type = "text/xml"

            print("Content-type: " + content_type)
            print

        print(content)
    def render(self, extent, size):
        mapObj = mapscript.mapObj(self.mapfile)

        mapObj.setConfigOption("MS_ERRORFILE", "stdout")
        mapObj.debug = 5

        mapObj.setExtent(extent.xMinimum(), extent.yMinimum(), extent.xMaximum(), extent.yMaximum())
        mapObj.setSize(int(size[0]), int(size[1]))
        self.messageTextEdit.append("Rendering " + extent.toString())

        mapscript.msIO_installStdoutToBuffer()

        mapImage = mapObj.draw()  # = mapscript.imageObj(int(size[0]), int(size[1]), self.mime_type)
        data = mapImage.getBytes()

        out = mapscript.msIO_getStdoutBufferString()
        mapscript.msIO_resetHandlers()
        self.messageTextEdit.append(out)

        return data
Example #6
0
def application(environ, start_response):
    try:
        req = mapscript.OWSRequest()
        req.loadParamsFromURL(environ.get('QUERY_STRING'))

        map = mapscript.mapObj(args.map_file)

        mapscript.msIO_installStdoutToBuffer()
        map.OWSDispatch(req)

        content_type = mapscript.msIO_stripStdoutBufferContentType()
        content = mapscript.msIO_getStdoutBufferBytes()

        if content_type == 'vnd.ogc.se_xml':
            content_type = 'text/xml'

        start_response('200 Ok', [('Content-type', content_type)])
        return [content]

    except:
        start_response('500 Ooops', [('Content-type', 'text/plain')])
        return ['An error occured\n' + mapscript.msIO_getStdoutBufferString()]
  def render(self, extent, size):
    mapObj = self.getMapObj()

    mapObj.setConfigOption("MS_ERRORFILE", "stdout")
    mapObj.debug = 5

    mapObj.setExtent(extent.xMinimum(), extent.yMinimum(), extent.xMaximum(), extent.yMaximum())
    mapObj.setSize(int(size[0]), int(size[1]))
    self.messageTextEdit.append( "Rendering " + extent.toString() )

    data = ''
    try:
      mapscript.msIO_installStdoutToBuffer()
      mapImage = mapObj.draw() #= mapscript.imageObj(int(size[0]), int(size[1]), self.mime_type)
      data = mapImage.getBytes()
      self.messageTextEdit.append( "Image size: " + str(len(data)) )

      out = mapscript.msIO_getStdoutBufferString()
      mapscript.msIO_resetHandlers()
      self.messageTextEdit.append( out )
    except mapscript.MapServerError as err:
      self.messageTextEdit.append( str(err) )

    return data
Example #8
0
#!/usr/bin/env python

import sys
import mapscript

req = mapscript.OWSRequest()
req.loadParams()

mapscript.msIO_installStdoutToBuffer()

map.OWSDispatch( req )

print 'Content-type: text/plain'
print
print mapscript.msIO_getStdoutBufferString()