1 |
jan |
1713 |
# Copyright (c) 2003 by Intevation GmbH |
2 |
|
|
# Authors: |
3 |
|
|
# Jan-Oliver Wagner <[email protected]> |
4 |
|
|
# |
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 |
|
|
|
19 |
|
|
import support |
20 |
|
|
import shapelib |
21 |
|
|
from dbflib import DBFFile, FTString, FTInteger, FTDouble |
22 |
|
|
from Extensions.gns2shp.gns2shp import gns2shp |
23 |
|
|
|
24 |
|
|
class gns2shpTest(unittest.TestCase, support.FileTestMixin): |
25 |
|
|
|
26 |
|
|
def test(self): |
27 |
|
|
"""Test for correct creation of Shapefile from GNS text file format""" |
28 |
|
|
eq = self.assertEquals |
29 |
|
|
|
30 |
|
|
# create a temporary gns file (use liechtenstein as reference) |
31 |
|
|
filename = self.temp_file_name('test.gns') |
32 |
|
|
os.system('cp ls.txt %s' % filename) |
33 |
|
|
|
34 |
|
|
# convert the reference gns file to shapefile |
35 |
|
|
dest_filename = self.temp_file_name('test') |
36 |
|
|
n = gns2shp(filename, dest_filename) |
37 |
|
|
|
38 |
|
|
# is the number of shapes correct? |
39 |
|
|
eq(n, 88) # what gns2shp reports |
40 |
|
|
# and now the actually written ones |
41 |
|
|
shp = shapelib.ShapeFile(dest_filename) |
42 |
|
|
numshapes, shapetype, mins, maxs = shp.info() |
43 |
|
|
eq(numshapes, n) |
44 |
|
|
|
45 |
|
|
# correct shapefile type? |
46 |
|
|
eq(shapetype, shapelib.SHPT_POINT) |
47 |
|
|
|
48 |
|
|
# attribute data correct? |
49 |
|
|
field_types = { 'RC': FTInteger, |
50 |
|
|
'UFI': FTInteger, |
51 |
|
|
'UNI': FTInteger, |
52 |
|
|
'UTM': FTString, |
53 |
|
|
'JOG': FTString, |
54 |
|
|
'FC': FTString, |
55 |
|
|
'DSG': FTString, |
56 |
|
|
'PC': FTInteger, |
57 |
|
|
'CC1': FTString, |
58 |
|
|
'ADM1': FTString, |
59 |
|
|
'ADM2': FTString, |
60 |
|
|
'DIM': FTInteger, |
61 |
|
|
'CC2': FTString, |
62 |
|
|
'NT': FTString, |
63 |
|
|
'LC': FTString, |
64 |
|
|
'SHORT_FORM': FTString, |
65 |
|
|
'GENERIC': FTString, |
66 |
|
|
'SORT_NAME': FTString, |
67 |
|
|
'FULL_NAME': FTString, |
68 |
|
|
'FULL_ND': FTString, |
69 |
|
|
'MODIFY_DAT': FTString} |
70 |
|
|
dbf = DBFFile(dest_filename) |
71 |
|
|
eq(dbf.record_count(), n) # correct number of data sets? |
72 |
|
|
eq(dbf.field_count(), len(field_types)) # correct number of fields? |
73 |
|
|
for i in range(dbf.field_count()): |
74 |
|
|
ftype, name, width, prec = dbf.field_info(i) |
75 |
|
|
eq(ftype, field_types[name]) # field of correct type? |
76 |
|
|
|
77 |
|
|
if __name__ == "__main__": |
78 |
|
|
unittest.main() |