2009-05-01 03:24:12 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from nose.tools import *
|
|
|
|
from utilities import execution_path
|
|
|
|
|
2010-03-11 19:12:22 +01:00
|
|
|
import os, mapnik2
|
2009-05-01 03:24:12 +02:00
|
|
|
|
|
|
|
def setup():
|
|
|
|
# All of the paths used are relative, if we run the tests
|
|
|
|
# from another directory we need to chdir()
|
|
|
|
os.chdir(execution_path('.'))
|
|
|
|
|
|
|
|
def test_field_listing():
|
2010-03-11 19:12:22 +01:00
|
|
|
lyr = mapnik2.Layer('test')
|
|
|
|
lyr.datasource = mapnik2.Shapefile(file='../data/shp/poly.shp')
|
2009-05-01 03:24:12 +02:00
|
|
|
fields = lyr.datasource.fields()
|
2009-05-01 03:42:58 +02:00
|
|
|
eq_(fields, ['AREA', 'EAS_ID', 'PRFEDEA'])
|
|
|
|
|
2010-11-14 09:56:42 +01:00
|
|
|
def test_total_feature_count_shp():
|
2010-03-11 19:12:22 +01:00
|
|
|
lyr = mapnik2.Layer('test')
|
|
|
|
lyr.datasource = mapnik2.Shapefile(file='../data/shp/poly.shp')
|
2009-05-01 03:42:58 +02:00
|
|
|
features = lyr.datasource.all_features()
|
|
|
|
num_feats = len(features)
|
|
|
|
eq_(num_feats, 10)
|
|
|
|
|
2010-11-14 09:56:42 +01:00
|
|
|
def test_total_feature_count_json():
|
|
|
|
lyr = mapnik2.Layer('test')
|
|
|
|
lyr.datasource = mapnik2.Ogr(file='../data/json/points.json',layer_by_index=0)
|
|
|
|
features = lyr.datasource.all_features()
|
|
|
|
num_feats = len(features)
|
2010-11-14 10:32:55 +01:00
|
|
|
eq_(num_feats, 5)
|
|
|
|
|
|
|
|
def test_reading_json_from_string():
|
|
|
|
json = open('../data/json/points.json','r').read()
|
|
|
|
lyr = mapnik2.Layer('test')
|
|
|
|
lyr.datasource = mapnik2.Ogr(file=json,layer_by_index=0)
|
|
|
|
features = lyr.datasource.all_features()
|
|
|
|
num_feats = len(features)
|
|
|
|
eq_(num_feats, 5)
|
2010-11-14 09:56:42 +01:00
|
|
|
|
2009-05-01 03:42:58 +02:00
|
|
|
def test_feature_envelope():
|
2010-03-11 19:12:22 +01:00
|
|
|
lyr = mapnik2.Layer('test')
|
|
|
|
lyr.datasource = mapnik2.Shapefile(file='../data/shp/poly.shp')
|
2009-05-01 03:42:58 +02:00
|
|
|
features = lyr.datasource.all_features()
|
|
|
|
for feat in features:
|
|
|
|
env = feat.envelope()
|
|
|
|
contains = lyr.envelope().contains(env)
|
|
|
|
eq_(contains, True)
|
|
|
|
intersects = lyr.envelope().contains(env)
|
|
|
|
eq_(intersects, True)
|
|
|
|
|
|
|
|
def test_feature_attributes():
|
2010-03-11 19:12:22 +01:00
|
|
|
lyr = mapnik2.Layer('test')
|
|
|
|
lyr.datasource = mapnik2.Shapefile(file='../data/shp/poly.shp')
|
2009-05-01 03:42:58 +02:00
|
|
|
features = lyr.datasource.all_features()
|
|
|
|
feat = features[0]
|
|
|
|
attrs = {'PRFEDEA': u'35043411', 'EAS_ID': 168, 'AREA': 215229.266}
|
|
|
|
eq_(feat.attributes, attrs)
|
2009-07-23 20:20:10 +02:00
|
|
|
eq_(lyr.datasource.fields(),['AREA', 'EAS_ID', 'PRFEDEA'])
|
|
|
|
eq_(lyr.datasource.field_types(),[float,int,str])
|
2009-05-01 03:42:58 +02:00
|
|
|
|