コード例 #1
0
def test_query_resolution():
    bbox = (-180, -90, 180, 90)
    init_res = (4.5, 6.7)
    query = mapnik.Query(mapnik.Box2d(*bbox), init_res)
    r = query.resolution
    assert_almost_equal(r[0], init_res[0], places=7)
    assert_almost_equal(r[1], init_res[1], places=7)
コード例 #2
0
def test_shapefile_polygon_feature_query_id():
    bbox = (15523428.2632, 4110477.6323, -11218494.8310, 7495720.7404)
    query = mapnik.Query(mapnik.Box2d(*bbox))
    if 'ogr' in mapnik.DatasourceCache.instance().plugin_names():
        ds = mapnik.Ogr(file='../data/shp/world_merc.shp', layer_by_index=0)
        for fld in ds.fields():
            query.add_property_name(fld)
        compare_shape_between_mapnik_and_ogr('../data/shp/world_merc.shp',
                                             query)
コード例 #3
0
 def test_that_nonexistant_query_field_throws(**kwargs):
     ds = mapnik.Osm(file='../data/osm/nodes.osm')
     eq_(len(ds.fields()), 0)
     query = mapnik.Query(ds.envelope())
     for fld in ds.fields():
         query.add_property_name(fld)
     # also add an invalid one, triggering throw
     query.add_property_name('bogus')
     ds.features(query)
コード例 #4
0
def test_query_init():
    bbox = (-180, -90, 180, 90)
    query = mapnik.Query(mapnik.Box2d(*bbox))
    r = query.resolution
    assert_almost_equal(r[0], 1.0, places=7)
    assert_almost_equal(r[1], 1.0, places=7)
    # https://github.com/mapnik/mapnik/issues/1762
    eq_(query.property_names, [])
    query.add_property_name('migurski')
    eq_(query.property_names, ['migurski'])
コード例 #5
0
ファイル: csv_test.py プロジェクト: magicdoughnut/PaperPlaces
 def test_that_nonexistant_query_field_throws(**kwargs):
     ds = get_csv_ds('lon_lat.csv')
     eq_(len(ds.fields()), 2)
     eq_(ds.fields(), ['lon', 'lat'])
     eq_(ds.field_types(), ['int', 'int'])
     query = mapnik.Query(ds.envelope())
     for fld in ds.fields():
         query.add_property_name(fld)
     # also add an invalid one, triggering throw
     query.add_property_name('bogus')
     ds.features(query)
コード例 #6
0
 def test_that_nonexistant_query_field_throws(**kwargs):
     ds = mapnik.Ogr(file='../data/shp/world_merc.shp',layer_by_index=0)
     eq_(len(ds.fields()),11)
     eq_(ds.fields(),['FIPS', 'ISO2', 'ISO3', 'UN', 'NAME', 'AREA', 'POP2005', 'REGION', 'SUBREGION', 'LON', 'LAT'])
     eq_(ds.field_types(),['str', 'str', 'str', 'int', 'str', 'int', 'int', 'int', 'int', 'float', 'float'])
     query = mapnik.Query(ds.envelope())
     for fld in ds.fields():
         query.add_property_name(fld)
     # also add an invalid one, triggering throw
     query.add_property_name('bogus')
     ds.features(query)
コード例 #7
0
ファイル: postgis_test.py プロジェクト: wl198302/mapnik
 def test_that_nonexistant_query_field_throws(**kwargs):
     ds = mapnik.PostGIS(dbname=MAPNIK_TEST_DBNAME, table='empty')
     eq_(len(ds.fields()), 1)
     eq_(ds.fields(), ['key'])
     eq_(ds.field_types(), ['int'])
     query = mapnik.Query(ds.envelope())
     for fld in ds.fields():
         query.add_property_name(fld)
     # also add an invalid one, triggering throw
     query.add_property_name('bogus')
     fs = ds.features(query)
コード例 #8
0
ファイル: osm_test.py プロジェクト: madunic/mapnik
 def test_that_nonexistant_query_field_throws(**kwargs):
     ds = mapnik.Osm(file='../data/osm/nodes.osm')
     # ugh, more odd stuff hardcoded...
     eq_(len(ds.fields()), 5)
     eq_(ds.fields(), ['bicycle', 'foot', 'horse', 'name', 'width'])
     eq_(ds.field_types(), ['str', 'str', 'str', 'str', 'str'])
     query = mapnik.Query(ds.envelope())
     for fld in ds.fields():
         query.add_property_name(fld)
     # also add an invalid one, triggering throw
     query.add_property_name('bogus')
     fs = ds.features(query)
コード例 #9
0
 def test_that_nonexistant_query_field_throws(**kwargs):
     ds = mapnik.SQLite(file='../data/sqlite/empty.db',
         table='empty',
         )
     eq_(len(ds.fields()),25)
     eq_(ds.fields(),['OGC_FID', 'scalerank', 'labelrank', 'featurecla', 'sovereignt', 'sov_a3', 'adm0_dif', 'level', 'type', 'admin', 'adm0_a3', 'geou_dif', 'name', 'abbrev', 'postal', 'name_forma', 'terr_', 'name_sort', 'map_color', 'pop_est', 'gdp_md_est', 'fips_10_', 'iso_a2', 'iso_a3', 'iso_n3'])
     eq_(ds.field_types(),['int', 'int', 'int', 'str', 'str', 'str', 'float', 'float', 'str', 'str', 'str', 'float', 'str', 'str', 'str', 'str', 'str', 'str', 'float', 'float', 'float', 'float', 'str', 'str', 'float'])
     query = mapnik.Query(ds.envelope())
     for fld in ds.fields():
         query.add_property_name(fld)
     # also add an invalid one, triggering throw
     query.add_property_name('bogus')
     fs = ds.features(query)
コード例 #10
0
ファイル: csv_test.py プロジェクト: lancha90/mapnik
 def test_lon_lat_detection(**kwargs):
     ds = get_csv_ds('lng_lat.csv')
     eq_(len(ds.fields()), 2)
     eq_(ds.fields(), ['lng', 'lat'])
     eq_(ds.field_types(), ['int', 'int'])
     query = mapnik.Query(ds.envelope())
     for fld in ds.fields():
         query.add_property_name(fld)
     fs = ds.features(query)
     desc = ds.describe()
     eq_(desc['geometry_type'], mapnik.DataGeometryType.Point)
     feat = fs.next()
     attr = {'lng': 0, 'lat': 0}
     eq_(feat.attributes, attr)
コード例 #11
0
    def test_rtree_creation():

        index = DB + '.index'
        if os.path.exists(index):
            os.unlink(index)

        threads = []
        for i in range(NUM_THREADS):
            t = threading.Thread(target=create_ds)
            t.start()
            threads.append(t)

        for i in threads:
            i.join()

        eq_(os.path.exists(index), True)
        conn = sqlite3.connect(index)
        cur = conn.cursor()
        try:
            cur.execute("Select count(*) from idx_%s_GEOMETRY" %
                        TABLE.replace("'", ""))
            conn.commit()
            eq_(cur.fetchone()[0], TOTAL)
        except sqlite3.OperationalError:
            # don't worry about testing # of index records if
            # python's sqlite module does not support rtree
            pass
        cur.close()

        ds = mapnik.SQLite(file=DB, table=TABLE)
        fs = ds.all_features()
        eq_(len(fs), TOTAL)
        os.unlink(index)
        ds = mapnik.SQLite(file=DB, table=TABLE, use_spatial_index=False)
        fs = ds.all_features()
        eq_(len(fs), TOTAL)
        eq_(os.path.exists(index), False)

        ds = mapnik.SQLite(file=DB, table=TABLE, use_spatial_index=True)
        fs = ds.all_features()
        for feat in fs:
            query = mapnik.Query(feat.envelope())
            selected = ds.features(query)
            eq_(len(selected.features) >= 1, True)

        eq_(os.path.exists(index), True)
        os.unlink(index)
コード例 #12
0
def test_feature_hit_count():
    raise Todo("need to optimize multigeom bbox handling in shapeindex")
    # results in different results between shp and ogr!
    #bbox = (-14284551.8434, 2074195.1992, -7474929.8687, 8140237.7628)
    bbox = (1113194.91, 4512803.085, 2226389.82, 6739192.905)
    query = mapnik.Query(mapnik.Box2d(*bbox))
    if 'ogr' in mapnik.DatasourceCache.instance().plugin_names():
        ds1 = mapnik.Ogr(file='../data/shp/world_merc.shp', layer_by_index=0)
        for fld in ds1.fields():
            query.add_property_name(fld)
        ds2 = mapnik.Shapefile(file='../data/shp/world_merc.shp')
        count1 = len(ds1.features(query).features)
        count2 = len(ds2.features(query).features)
        eq_(
            count1, count2,
            "Feature count differs between OGR driver (%s features) and Shapefile Driver (%s features) when querying the same bbox"
            % (count1, count2))
コード例 #13
0
ファイル: shapefile_test.py プロジェクト: yuanhhy/mapnik
 def test_dbf_logical_field_is_boolean():
     ds = mapnik.Shapefile(file='../data/shp/long_lat')
     eq_(len(ds.fields()),7)
     eq_(ds.fields(),['LONG', 'LAT', 'LOGICAL_TR', 'LOGICAL_FA', 'CHARACTER', 'NUMERIC', 'DATE'])
     eq_(ds.field_types(),['str', 'str', 'bool', 'bool', 'str', 'float', 'str'])
     query = mapnik.Query(ds.envelope())
     for fld in ds.fields():
         query.add_property_name(fld)
     feat = ds.all_features()[0]
     eq_(feat.id(),1)
     eq_(feat['LONG'],'0')
     eq_(feat['LAT'],'0')
     eq_(feat['LOGICAL_TR'],True)
     eq_(feat['LOGICAL_FA'],False)
     eq_(feat['CHARACTER'],'254')
     eq_(feat['NUMERIC'],32)
     eq_(feat['DATE'],'20121202')
コード例 #14
0
    def test_rasterlite():
        ds = mapnik.Rasterlite(file='../data/rasterlite/globe.sqlite',
                               table='globe')
        e = ds.envelope()

        assert_almost_equal(e.minx, -180, places=5)
        assert_almost_equal(e.miny, -90, places=5)
        assert_almost_equal(e.maxx, 180, places=5)
        assert_almost_equal(e.maxy, 90, places=5)
        eq_(len(ds.fields()), 0)
        query = mapnik.Query(ds.envelope())
        for fld in ds.fields():
            query.add_property_name(fld)
        fs = ds.features(query)
        feat = fs.next()
        eq_(feat.id(), 1)
        eq_(feat.attributes, {})
コード例 #15
0
ファイル: csv_test.py プロジェクト: eightysteele/mapnik
 def test_that_nonexistant_query_field_throws(**kwargs):
     ds = get_csv_ds('lon_lat.csv')
     eq_(len(ds.fields()), 2)
     eq_(ds.fields(), ['lon', 'lat'])
     eq_(ds.field_types(), ['int', 'int'])
     query = mapnik.Query(ds.envelope())
     for fld in ds.fields():
         query.add_property_name(fld)
     # also add an invalid one, triggering throw
     query.add_property_name('bogus')
     fs = ds.features(query)
     eq_(
         ds.describe(), {
             'geometry_type': mapnik.DataGeometryType.Point,
             'type': mapnik.DataType.Vector,
             'name': 'csv',
             'encoding': 'utf-8'
         })
コード例 #16
0
feature.add_geometries_from_wkt('POINT (1 1)')
paths = feature.geometries()
print paths.__geo_interface__

def print_featureset(fs):
	feat = fs.next()
	while (feat):
	    print feat.__geo_interface__
	    try:
	        feat = fs.next()
	    except StopIteration:
	        feat = None

# Example 3:  access via an inline Geo-CSV
csv = '''
id,wkt
1,"POINT(0 0)"
2,"POINT(1 1)"
'''
datasource = mapnik.Datasource(**{'type':'csv','inline':csv})
query = mapnik.Query(datasource.envelope())
fs = datasource.features(query)
print_featureset(fs)


# Example 3:  access via a shapefile
# uncomment and fix the path to point to a valid shapefile
#datasource = mapnik.Datasource(**{'type':'shape','file':'some/path/to/shapefile.shp'})
#query = mapnik.Query(datasource.envelope())
#print_featureset(datasource.features(query))
コード例 #17
0
def test_query_init():
    bbox = (-180, -90, 180, 90)
    query = mapnik.Query(mapnik.Box2d(*bbox))
    r = query.resolution
    assert_almost_equal(r[0], 1.0, places=7)
    assert_almost_equal(r[1], 1.0, places=7)