#!/usr/bin/env python

from nose.tools import *

from utilities import execution_path

import os, sys, glob, mapnik2

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_shapefile_feature_id():

    ds = mapnik2.Shapefile(file='../data/shp/polylines.shp')
    fs = ds.featureset()
    eq_(1, fs.next().id())
    eq_(2, fs.next().id())
    count = 0
    while True:
        feature = fs.next()
        if not feature:
            break
        count = feature.id()
    eq_(count,11)

    ds = mapnik2.Ogr(file='../data/shp/polylines.shp',layer_by_index=0)
    fs = ds.featureset()
    eq_(1, fs.next().id())
    eq_(2, fs.next().id())
    count = 0
    while True:
        feature = fs.next()
        if not feature:
            break
        count = feature.id()
    eq_(count,11)



if __name__ == "__main__":
    setup()
    test_shapefile_feature_id()
@@ -277,44 +277,130 @@
 def 
-test_shapefile_feature_id():%0A
+compare_shape_between_mapnik_and_ogr(shapefile,query=None):%0A    ds1 = mapnik2.Ogr(file=shapefile,layer_by_index=0)
 %0A    ds
+2
  = m
@@ -425,48 +425,84 @@
 ile=
-'../data/shp/polylines.shp')%0A
+shapefile)%0A    if query:%0A        fs1 = ds1.features(query)%0A  
     
+  
 fs
+2
  = ds
+2
 .fea
@@ -510,65 +510,86 @@
 ures
-et(
+(query
 )%0A    e
-q_(1, fs.next().id
+lse:%0A        fs1 = ds1.featureset
 ()
-)
 %0A    
-eq_(2, fs.next().id()
+    fs2 = ds2.featureset(
 )%0A  
@@ -591,32 +591,33 @@
 ()%0A    count = 0
+;
 %0A    while True:
@@ -602,37 +602,38 @@
 t = 0;%0A    while
- 
+(
 True
+)
 :%0A        featur
@@ -622,36 +622,81 @@
 e):%0A        
-feature
+count += 1%0A        feat1 = fs1.next()%0A        feat2
  = fs
+2
 .next()%0A    
@@ -702,35 +702,33 @@
      if not feat
-ure
+1
 :%0A            br
@@ -735,39 +735,160 @@
 eak%0A        
-count =
+#import pdb;pdb.set_trace()%0A        eq_(feat1.id(),feat2.id(),%0A            '%25s : ogr feature id %25s %22%25s%22 does not equal shapefile
  feature
 .id()%0A    eq
@@ -879,329 +879,876 @@
 ture
-.id()%0A    eq_(count,11)%0A%0A    ds = mapnik2.Ogr(file='../data/shp/polylines.shp',layer_by_index=0)%0A    fs = ds.featureset
+ id %25s %22%25s%22' %0A              %25 (count,feat1.id(),str(feat1.attributes), feat2.id(),str(feat2.attributes)) )%0A        %0A    return True%0A    %0A%0A%0Adef test_shapefile_line_featureset_id():%0A    compare_shape_between_mapnik_and_ogr('../data/shp/polylines.shp')%0A%0Adef test_shapefile_polygon_featureset_id():%0A    compare_shape_between_mapnik_and_ogr('../data/shp/poly.shp')%0A%0Adef test_shapefile_polygon_feature_query_id
 ()
+:
 %0A    
-eq_(1, fs.next().id())%0A    eq_(2, fs.next().id())%0A    count = 0%0A    while True:%0A        feature = fs.next()%0A        if not feature:%0A            break%0A        count = feature.id()%0A    eq_(count,11
+# results in different results between shp and ogr!%0A    #bbox = (-14284551.8434, 2074195.1992, -7474929.8687, 8140237.7628)%0A    bbox = (15523428.2632, 4110477.6323, -11218494.8310, 7495720.7404)%0A    query = mapnik2.Query(mapnik2.Box2d(*bbox))%0A    ds = mapnik2.Ogr(file='../data/shp/world_merc.shp',layer_by_index=0)%0A    for fld in ds.fields():%0A        query.add_property_name(fld)%0A    compare_shape_between_mapnik_and_ogr('../data/shp/world_merc.shp',query
 )%0A%0A%0A
@@ -1806,20 +1806,117 @@
 apefile_
+line_
 feature
+set_id()%0A    test_shapefile_polygon_featureset_id()%0A    test_shapefile_polygon_feature_query
 _id()

improve feature id test: make sure to test restricted query extents and start testing various geometry types