コード例 #1
0
ファイル: coords.py プロジェクト: rpcarver/TopOSM
def getTileRange(envLL, z, ntiles=1):
    """Returns the tile number range (fromx, tox, fromy, toy)
    that covers the Box2d at the specified zoom level."""
    topleft = Coord(envLL.minx, envLL.maxy)
    bottomright = Coord(envLL.maxx, envLL.miny)
    tltile = getTileAtLL(topleft, z, ntiles)
    brtile = getTileAtLL(bottomright, z, ntiles)
    return (tltile[0], brtile[0], tltile[1], brtile[1])
コード例 #2
0
    def test_add_feature(self):
        md = self.makeOne()
        self.failUnlessEqual(md.num_features(), 0)
        from mapnik2 import Geometry2d
        md.add_feature(
            self.makeFeature(Geometry2d.from_wkt('Point(2 3)'), foo='bar'))
        self.failUnlessEqual(md.num_features(), 1)

        from mapnik2 import Coord
        retrieved = md.features_at_point(Coord(2, 3)).features
        self.failUnlessEqual(len(retrieved), 1)
        f = retrieved[0]
        self.failUnlessEqual(f['foo'], 'bar')

        retrieved = md.features_at_point(Coord(20, 30)).features
        self.failUnlessEqual(len(retrieved), 0)
コード例 #3
0
    def test_add_feature(self):
        try:
            from shapely.geometry import Point
        except ImportError:
            raise Todo("Make this test not dependant on shapely")

        md = self.makeOne()
        self.failUnlessEqual(md.num_features(), 0)
        md.add_feature(self.makeFeature(Point(2, 3), foo='bar'))
        self.failUnlessEqual(md.num_features(), 1)

        from mapnik2 import Coord
        retrieved = md.features_at_point(Coord(2, 3)).features
        self.failUnlessEqual(len(retrieved), 1)
        f = retrieved[0]
        self.failUnlessEqual(f['foo'], 'bar')

        retrieved = md.features_at_point(Coord(20, 30)).features
        self.failUnlessEqual(len(retrieved), 0)
コード例 #4
0
ファイル: wms130.py プロジェクト: drewjelani/OGCServer
    def GetCapabilities(self, params):
        if not self.capabilities:
            capetree = ElementTree.fromstring(self.capabilitiesxmltemplate)

            elements = capetree.findall(
                '{http://www.opengis.net/wms}Capability//{http://www.opengis.net/wms}OnlineResource'
            )
            for element in elements:
                element.set('{http://www.w3.org/1999/xlink}href',
                            self.opsonlineresource)

            self.processServiceCapabilities(capetree)

            rootlayerelem = capetree.find(
                '{http://www.opengis.net/wms}Capability/{http://www.opengis.net/wms}Layer'
            )

            rootlayername = ElementTree.Element('Name')
            if self.conf.has_option('map', 'wms_name'):
                rootlayername.text = to_unicode(
                    self.conf.get('map', 'wms_name'))
            else:
                rootlayername.text = '__all__'
            rootlayerelem.append(rootlayername)

            rootlayertitle = ElementTree.Element('Title')
            if self.conf.has_option('map', 'wms_title'):
                rootlayertitle.text = to_unicode(
                    self.conf.get('map', 'wms_title'))
            else:
                rootlayertitle.text = 'OGCServer WMS Server'
            rootlayerelem.append(rootlayertitle)

            rootlayerabstract = ElementTree.Element('Abstract')
            if self.conf.has_option('map', 'wms_abstract'):
                rootlayerabstract.text = to_unicode(
                    self.conf.get('map', 'wms_abstract'))
            else:
                rootlayerabstract.text = 'OGCServer WMS Server'
            rootlayerelem.append(rootlayerabstract)

            for epsgcode in self.allowedepsgcodes:
                rootlayercrs = ElementTree.Element('CRS')
                rootlayercrs.text = epsgcode.upper()
                rootlayerelem.append(rootlayercrs)

            for layer in self.mapfactory.ordered_layers:
                layerproj = Projection(layer.srs)
                layername = ElementTree.Element('Name')
                layername.text = to_unicode(layer.name)
                env = layer.envelope()
                layerexgbb = ElementTree.Element('EX_GeographicBoundingBox')
                ll = layerproj.inverse(Coord(env.minx, env.miny))
                ur = layerproj.inverse(Coord(env.maxx, env.maxy))
                exgbb_wbl = ElementTree.Element('westBoundLongitude')
                exgbb_wbl.text = str(ll.x)
                layerexgbb.append(exgbb_wbl)
                exgbb_ebl = ElementTree.Element('eastBoundLongitude')
                exgbb_ebl.text = str(ur.x)
                layerexgbb.append(exgbb_ebl)
                exgbb_sbl = ElementTree.Element('southBoundLatitude')
                exgbb_sbl.text = str(ll.y)
                layerexgbb.append(exgbb_sbl)
                exgbb_nbl = ElementTree.Element('northBoundLatitude')
                exgbb_nbl.text = str(ur.y)
                layerexgbb.append(exgbb_nbl)
                layerbbox = ElementTree.Element('BoundingBox')
                if layer.wms_srs:
                    layerbbox.set('CRS', layer.wms_srs)
                else:
                    layerbbox.set('CRS', layerproj.epsgstring())
                layerbbox.set('minx', str(env.minx))
                layerbbox.set('miny', str(env.miny))
                layerbbox.set('maxx', str(env.maxx))
                layerbbox.set('maxy', str(env.maxy))
                layere = ElementTree.Element('Layer')
                layere.append(layername)
                layertitle = ElementTree.Element('Title')
                if hasattr(layer, 'title'):
                    layertitle.text = to_unicode(layer.title)
                else:
                    layertitle.text = to_unicode(layer.name)
                layere.append(layertitle)
                layerabstract = ElementTree.Element('Abstract')
                if hasattr(layer, 'abstract'):
                    layerabstract.text = to_unicode(layer.abstract)
                else:
                    layerabstract.text = 'no abstract'
                layere.append(layerabstract)
                if layer.queryable:
                    layere.set('queryable', '1')
                layere.append(layerexgbb)
                layere.append(layerbbox)
                if len(layer.wmsextrastyles) > 0:
                    for extrastyle in [layer.wmsdefaultstyle] + list(
                            layer.wmsextrastyles):
                        style = ElementTree.Element('Style')
                        stylename = ElementTree.Element('Name')
                        stylename.text = to_unicode(extrastyle)
                        styletitle = ElementTree.Element('Title')
                        styletitle.text = to_unicode(extrastyle)
                        style.append(stylename)
                        style.append(styletitle)
                        layere.append(style)
                rootlayerelem.append(layere)
            self.capabilities = '<?xml version="1.0" encoding="UTF-8"?>' + ElementTree.tostring(
                capetree, encoding='UTF-8', pretty_print=True)
        response = Response('text/xml', self.capabilities)
        return response
コード例 #5
0
 def forward(self, x, y):
     if not self.proj:
         self.proj = Projection('+init=%s:%s' % (self.namespace, self.code))
     return self.proj.forward(Coord(x, y))
コード例 #6
0
 def inverse(self, x, y):
     if not self.proj:
         self.proj = Projection('+init=%s:%s' % (self.namespace, self.code))
     return self.proj.inverse(Coord(x, y))
コード例 #7
0
    def GetCapabilities(self, params):
        if not self.capabilities:
            capetree = ElementTree.fromstring(self.capabilitiesxmltemplate)

            elements = capetree.findall('Capability//OnlineResource')
            for element in elements:
                element.set('{http://www.w3.org/1999/xlink}href',
                            self.opsonlineresource)

            self.processServiceCapabilities(capetree)

            rootlayerelem = capetree.find(
                '{http://www.opengis.net/wms}Capability/{http://www.opengis.net/wms}Layer'
            )

            for epsgcode in self.allowedepsgcodes:
                rootlayercrs = ElementTree.Element('SRS')
                rootlayercrs.text = epsgcode.upper()
                rootlayerelem.append(rootlayercrs)

            for layer in self.mapfactory.ordered_layers:
                layerproj = Projection(layer.srs)
                layername = ElementTree.Element('Name')
                layername.text = layer.name
                env = layer.envelope()
                llp = layerproj.inverse(Coord(env.minx, env.miny))
                urp = layerproj.inverse(Coord(env.maxx, env.maxy))
                latlonbb = ElementTree.Element('LatLonBoundingBox')
                latlonbb.set('minx', str(llp.x))
                latlonbb.set('miny', str(llp.y))
                latlonbb.set('maxx', str(urp.x))
                latlonbb.set('maxy', str(urp.y))
                layerbbox = ElementTree.Element('BoundingBox')
                layerbbox.set('SRS', layerproj.epsgstring())
                layerbbox.set('minx', str(env.minx))
                layerbbox.set('miny', str(env.miny))
                layerbbox.set('maxx', str(env.maxx))
                layerbbox.set('maxy', str(env.maxy))
                layere = ElementTree.Element('Layer')
                layere.append(layername)
                if layer.title:
                    layertitle = ElementTree.Element('Title')
                    layertitle.text = layer.title
                    layere.append(layertitle)
                if layer.abstract:
                    layerabstract = ElementTree.Element('Abstract')
                    layerabstract.text = layer.abstract
                    layere.append(layerabstract)
                if layer.queryable:
                    layere.set('queryable', '1')
                layere.append(latlonbb)
                layere.append(layerbbox)
                if len(layer.wmsextrastyles) > 0:
                    for extrastyle in [layer.wmsdefaultstyle] + list(
                            layer.wmsextrastyles):
                        style = ElementTree.Element('Style')
                        stylename = ElementTree.Element('Name')
                        stylename.text = extrastyle
                        styletitle = ElementTree.Element('Title')
                        styletitle.text = extrastyle
                        style.append(stylename)
                        style.append(styletitle)
                        layere.append(style)
                rootlayerelem.append(layere)
            self.capabilities = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n' + ElementTree.tostring(
                capetree)
        response = Response('application/vnd.ogc.wms_xml', self.capabilities)
        return response
コード例 #8
0
def convert_loc(line):
    britishProj = Projection('+init=epsg:27700') # British National Grid

    c = Coord(float(line[2]), float(line[3]))
    c = britishProj.inverse(c)  ## Coord now in Lat/Lng
    return c
コード例 #9
0
ファイル: coords.py プロジェクト: rpcarver/TopOSM
 def envPixelToLL(self, env, zoom):
     lb = self.pixelToLL(Coord(env.minx, env.miny), zoom)
     rt = self.pixelToLL(Coord(env.maxx, env.maxy), zoom)
     return Box2d(lb.x, lb.y, rt.x, rt.y)
コード例 #10
0
ファイル: coords.py プロジェクト: rpcarver/TopOSM
 def envLLToPixel(self, env, zoom):
     lb = self.LLToPixel(Coord(env.minx, env.miny), zoom)
     rt = self.LLToPixel(Coord(env.maxx, env.maxy), zoom)
     return Box2d(lb.x, lb.y, rt.x, rt.y)
コード例 #11
0
ファイル: coords.py プロジェクト: rpcarver/TopOSM
 def pixelToLL(self, coord, zoom):
     e = self.zc[zoom]
     f = (coord.x - e[0]) / self.Bc[zoom]
     g = (coord.y - e[1]) / -self.Cc[zoom]
     h = RAD_TO_DEG * (2 * atan(exp(g)) - 0.5 * pi)
     return Coord(f, h)
コード例 #12
0
ファイル: coords.py プロジェクト: rpcarver/TopOSM
 def LLToPixel(self, coord, zoom):
     d = self.zc[zoom]
     e = round(d[0] + coord.x * self.Bc[zoom])
     f = minmax(sin(DEG_TO_RAD * coord.y), -0.9999, 0.9999)
     g = round(d[1] + 0.5 * log((1 + f) / (1 - f)) * -self.Cc[zoom])
     return Coord(e, g)