1 |
jan |
2484 |
# Copyright (c) 2003, 2004 by Intevation GmbH |
2 |
jan |
1713 |
# Authors: |
3 |
jan |
2484 |
# Jan-Oliver Wagner <[email protected]> (2003, 2004) |
4 |
jan |
1713 |
# |
5 |
|
|
# This program is free software under the GPL (>=v2) |
6 |
|
|
# Read the file COPYING coming with Thuban for details. |
7 |
|
|
|
8 |
|
|
""" |
9 |
|
|
Test gns2shp extension. |
10 |
|
|
""" |
11 |
|
|
|
12 |
|
|
__version__ = "$Revision$" |
13 |
|
|
# $Source$ |
14 |
|
|
# $Id$ |
15 |
|
|
|
16 |
|
|
import unittest |
17 |
|
|
import os |
18 |
jan |
2484 |
import sys |
19 |
jan |
1713 |
|
20 |
jan |
2484 |
# If run directly as a script, add Thuban's test directory, the Lib |
21 |
|
|
# directory and the Thuban directory itself to the path. |
22 |
|
|
# Otherwise we assume that the importing code as already done it |
23 |
|
|
if __name__ == "__main__": |
24 |
|
|
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), |
25 |
|
|
"..", "..", "..", "test")) |
26 |
|
|
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), |
27 |
|
|
"..", "..", "..", "Lib")) |
28 |
|
|
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), |
29 |
|
|
"..", "..", "..")) |
30 |
|
|
|
31 |
jan |
1713 |
import support |
32 |
|
|
import shapelib |
33 |
|
|
from dbflib import DBFFile, FTString, FTInteger, FTDouble |
34 |
|
|
from Extensions.gns2shp.gns2shp import gns2shp |
35 |
|
|
|
36 |
|
|
class gns2shpTest(unittest.TestCase, support.FileTestMixin): |
37 |
|
|
|
38 |
|
|
def test(self): |
39 |
|
|
"""Test for correct creation of Shapefile from GNS text file format""" |
40 |
|
|
eq = self.assertEquals |
41 |
|
|
|
42 |
|
|
# create a temporary gns file (use liechtenstein as reference) |
43 |
|
|
filename = self.temp_file_name('test.gns') |
44 |
|
|
os.system('cp ls.txt %s' % filename) |
45 |
|
|
|
46 |
|
|
# convert the reference gns file to shapefile |
47 |
|
|
dest_filename = self.temp_file_name('test') |
48 |
|
|
n = gns2shp(filename, dest_filename) |
49 |
|
|
|
50 |
|
|
# is the number of shapes correct? |
51 |
|
|
eq(n, 88) # what gns2shp reports |
52 |
|
|
# and now the actually written ones |
53 |
|
|
shp = shapelib.ShapeFile(dest_filename) |
54 |
|
|
numshapes, shapetype, mins, maxs = shp.info() |
55 |
|
|
eq(numshapes, n) |
56 |
|
|
|
57 |
|
|
# correct shapefile type? |
58 |
|
|
eq(shapetype, shapelib.SHPT_POINT) |
59 |
|
|
|
60 |
|
|
# attribute data correct? |
61 |
|
|
field_types = { 'RC': FTInteger, |
62 |
|
|
'UFI': FTInteger, |
63 |
|
|
'UNI': FTInteger, |
64 |
|
|
'UTM': FTString, |
65 |
|
|
'JOG': FTString, |
66 |
|
|
'FC': FTString, |
67 |
|
|
'DSG': FTString, |
68 |
|
|
'PC': FTInteger, |
69 |
|
|
'CC1': FTString, |
70 |
|
|
'ADM1': FTString, |
71 |
|
|
'ADM2': FTString, |
72 |
|
|
'DIM': FTInteger, |
73 |
|
|
'CC2': FTString, |
74 |
|
|
'NT': FTString, |
75 |
|
|
'LC': FTString, |
76 |
|
|
'SHORT_FORM': FTString, |
77 |
|
|
'GENERIC': FTString, |
78 |
|
|
'SORT_NAME': FTString, |
79 |
|
|
'FULL_NAME': FTString, |
80 |
|
|
'FULL_ND': FTString, |
81 |
|
|
'MODIFY_DAT': FTString} |
82 |
|
|
dbf = DBFFile(dest_filename) |
83 |
|
|
eq(dbf.record_count(), n) # correct number of data sets? |
84 |
|
|
eq(dbf.field_count(), len(field_types)) # correct number of fields? |
85 |
|
|
for i in range(dbf.field_count()): |
86 |
|
|
ftype, name, width, prec = dbf.field_info(i) |
87 |
|
|
eq(ftype, field_types[name]) # field of correct type? |
88 |
|
|
|
89 |
|
|
if __name__ == "__main__": |
90 |
|
|
unittest.main() |