Author: jbronn
Date: 2007-09-30 10:16:22 -0500 (Sun, 30 Sep 2007)
New Revision: 6440
Modified:
django/branches/gis/django/contrib/gis/gdal/geometries.py
django/branches/gis/django/contrib/gis/tests/geometries.py
django/branches/gis/django/contrib/gis/tests/test_gdal_geom.py
Log:
gis: gdal: fixed GML property, and added tests.
Modified: django/branches/gis/django/contrib/gis/gdal/geometries.py
===================================================================
--- django/branches/gis/django/contrib/gis/gdal/geometries.py 2007-09-30
04:19:31 UTC (rev 6439)
+++ django/branches/gis/django/contrib/gis/gdal/geometries.py 2007-09-30
15:16:22 UTC (rev 6440)
@@ -216,9 +216,9 @@
@property
def gml(self):
"Returns the GML representation of the Geometry."
- buf = c_char_p()
- check_err(lgdal.OGR_G_ExportToGML(self._g, byref(buf)))
- return string_at(buf)
+ buf = lgdal.OGR_G_ExportToGML(self._g)
+ if buf: return string_at(buf)
+ else: return None
@property
def wkt(self):
Modified: django/branches/gis/django/contrib/gis/tests/geometries.py
===================================================================
--- django/branches/gis/django/contrib/gis/tests/geometries.py 2007-09-30
04:19:31 UTC (rev 6439)
+++ django/branches/gis/django/contrib/gis/tests/geometries.py 2007-09-30
15:16:22 UTC (rev 6440)
@@ -33,14 +33,14 @@
TestGeom('GEOMETRYCOLLECTION(MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10,
0 0)),((20 20, 20 30, 30 30, 30 20, 20 20),(25 25, 25 26, 26 26, 26 25, 25
25))),MULTILINESTRING((0 0, 10 0, 10 10, 0 10),(20 20, 30 20)),MULTIPOINT(0 0,
10 0, 10 10, 0 10, 0 0))',
hex='010700000003000000010600000002000000010300000001000000050000000000000000000000000000000000000000000000000024400000000000000000000000000000244000000000000024400000000000000000000000000000244000000000000000000000000000000000010300000002000000050000000000000000003440000000000000344000000000000034400000000000003E400000000000003E400000000000003E400000000000003E40000000000000344000000000000034400000000000003440050000000000000000003940000000000000394000000000000039400000000000003A400000000000003A400000000000003A400000000000003A4000000000000039400000000000003940000000000000394001050000000200000001020000000400000000000000000000000000000000000000000000000000244000000000000000000000000000002440000000000000244000000000000000000000000000002440010200000002000000000000000000344000000000000034400000000000003E400000000000003440010400000005000000010100000000000000000000000000000000000000010100000000000000000024400000000000000000010100000000000000000024400000000000002440010100000000000000000000000000000000002440010100000000000000000000000000000000000000'),
)
-# WKT Output
-wkt_out = (TestGeom('POINT(110 130)', ewkt='POINT (110.0000000000000000
130.0000000000000000)',
kml='<Point><coordinates>110.0,130.0,0</coordinates></Point>'),
- TestGeom('LINESTRING(40 40, 50 130, 130 130)', ewkt='LINESTRING
(40.0000000000000000 40.0000000000000000, 50.0000000000000000
130.0000000000000000, 130.0000000000000000 130.0000000000000000)',
kml='<LineString><coordinates>40.0,40.0,0 50.0,130.0,0
130.0,130.0,0</coordinates></LineString>'),
- TestGeom('POLYGON((150 150, 410 150, 280 20, 20 20, 150 150),(170
120, 330 120, 260 50, 100 50, 170 120))', ewkt='POLYGON ((150.0000000000000000
150.0000000000000000, 410.0000000000000000 150.0000000000000000,
280.0000000000000000 20.0000000000000000, 20.0000000000000000
20.0000000000000000, 150.0000000000000000 150.0000000000000000),
(170.0000000000000000 120.0000000000000000, 330.0000000000000000
120.0000000000000000, 260.0000000000000000 50.0000000000000000,
100.0000000000000000 50.0000000000000000, 170.0000000000000000
120.0000000000000000))',
kml='<Polygon><outerBoundaryIs><LinearRing><coordinates>150.0,150.0,0
410.0,150.0,0 280.0,20.0,0 20.0,20.0,0
150.0,150.0,0</coordinates></LinearRing></outerBoundaryIs><innerBoundaryIs><LinearRing><coordinates>170.0,120.0,0
330.0,120.0,0 260.0,50.0,0 100.0,50.0,0
170.0,120.0,0</coordinates></LinearRing></innerBoundaryIs></Polygon>'),
- TestGeom('MULTIPOINT(10 80, 110 170, 110 120)', ewkt='MULTIPOINT
(10.0000000000000000 80.0000000000000000, 110.0000000000000000
170.0000000000000000, 110.0000000000000000 120.0000000000000000)',
kml='<MultiGeometry><Point><coordinates>10.0,80.0,0</coordinates></Point><Point><coordinates>110.0,170.0,0</coordinates></Point><Point><coordinates>110.0,120.0,0</coordinates></Point></MultiGeometry>'),
- TestGeom('MULTILINESTRING((110 100, 40 30, 180 30),(170 30, 110 90,
50 30))', ewkt='MULTILINESTRING ((110.0000000000000000 100.0000000000000000,
40.0000000000000000 30.0000000000000000, 180.0000000000000000
30.0000000000000000), (170.0000000000000000 30.0000000000000000,
110.0000000000000000 90.0000000000000000, 50.0000000000000000
30.0000000000000000))',
kml='<MultiGeometry><LineString><coordinates>110.0,100.0,0 40.0,30.0,0
180.0,30.0,0</coordinates></LineString><LineString><coordinates>170.0,30.0,0
110.0,90.0,0 50.0,30.0,0</coordinates></LineString></MultiGeometry>'),
- TestGeom('MULTIPOLYGON(((110 110, 70 200, 150 200, 110 110),(110
110, 100 180, 120 180, 110 110)),((110 110, 150 20, 70 20, 110 110),(110 110,
120 40, 100 40, 110 110)))', ewkt='MULTIPOLYGON (((110.0000000000000000
110.0000000000000000, 70.0000000000000000 200.0000000000000000,
150.0000000000000000 200.0000000000000000, 110.0000000000000000
110.0000000000000000), (110.0000000000000000 110.0000000000000000,
100.0000000000000000 180.0000000000000000, 120.0000000000000000
180.0000000000000000, 110.0000000000000000 110.0000000000000000)),
((110.0000000000000000 110.0000000000000000, 150.0000000000000000
20.0000000000000000, 70.0000000000000000 20.0000000000000000,
110.0000000000000000 110.0000000000000000), (110.0000000000000000
110.0000000000000000, 120.0000000000000000 40.0000000000000000,
100.0000000000000000 40.0000000000000000, 110.0000000000000000
110.0000000000000000)))',
kml='<MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>110.0,110.0,0
70.0,200.0,0 150.0,200.0,0
110.0,110.0,0</coordinates></LinearRing></outerBoundaryIs><innerBoundaryIs><LinearRing><coordinates>110.0,110.0,0
100.0,180.0,0 120.0,180.0,0
110.0,110.0,0</coordinates></LinearRing></innerBoundaryIs></Polygon><Polygon><outerBoundaryIs><LinearRing><coordinates>110.0,110.0,0
150.0,20.0,0 70.0,20.0,0
110.0,110.0,0</coordinates></LinearRing></outerBoundaryIs><innerBoundaryIs><LinearRing><coordinates>110.0,110.0,0
120.0,40.0,0 100.0,40.0,0
110.0,110.0,0</coordinates></LinearRing></innerBoundaryIs></Polygon></MultiGeometry>'),
- TestGeom('GEOMETRYCOLLECTION(POINT(110 260), LINESTRING(110 0, 110
60))', ewkt='GEOMETRYCOLLECTION (POINT (110.0000000000000000
260.0000000000000000), LINESTRING (110.0000000000000000 0.0000000000000000,
110.0000000000000000 60.0000000000000000))',
kml='<MultiGeometry><Point><coordinates>110.0,260.0,0</coordinates></Point><LineString><coordinates>110.0,0.0,0
110.0,60.0,0</coordinates></LineString></MultiGeometry>'),
+# WKT, GML, KML output
+wkt_out = (TestGeom('POINT (110 130)', ewkt='POINT (110.0000000000000000
130.0000000000000000)',
kml='<Point><coordinates>110.0,130.0,0</coordinates></Point>',
gml='<gml:Point><gml:coordinates>110,130</gml:coordinates></gml:Point>'),
+ TestGeom('LINESTRING (40 40,50 130,130 130)', ewkt='LINESTRING
(40.0000000000000000 40.0000000000000000, 50.0000000000000000
130.0000000000000000, 130.0000000000000000 130.0000000000000000)',
kml='<LineString><coordinates>40.0,40.0,0 50.0,130.0,0
130.0,130.0,0</coordinates></LineString>',
gml='<gml:LineString><gml:coordinates>40,40 50,130
130,130</gml:coordinates></gml:LineString>'),
+ TestGeom('POLYGON ((150 150,410 150,280 20,20 20,150 150),(170
120,330 120,260 50,100 50,170 120))', ewkt='POLYGON ((150.0000000000000000
150.0000000000000000, 410.0000000000000000 150.0000000000000000,
280.0000000000000000 20.0000000000000000, 20.0000000000000000
20.0000000000000000, 150.0000000000000000 150.0000000000000000),
(170.0000000000000000 120.0000000000000000, 330.0000000000000000
120.0000000000000000, 260.0000000000000000 50.0000000000000000,
100.0000000000000000 50.0000000000000000, 170.0000000000000000
120.0000000000000000))',
kml='<Polygon><outerBoundaryIs><LinearRing><coordinates>150.0,150.0,0
410.0,150.0,0 280.0,20.0,0 20.0,20.0,0
150.0,150.0,0</coordinates></LinearRing></outerBoundaryIs><innerBoundaryIs><LinearRing><coordinates>170.0,120.0,0
330.0,120.0,0 260.0,50.0,0 100.0,50.0,0
170.0,120.0,0</coordinates></LinearRing></innerBoundaryIs></Polygon>',
gml='<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>150,150
410,150 280,20 20,20
150,150</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>170,120
330,120 260,50 100,50
170,120</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon>'),
+ TestGeom('MULTIPOINT (10 80,110 170,110 120)', ewkt='MULTIPOINT
(10.0000000000000000 80.0000000000000000, 110.0000000000000000
170.0000000000000000, 110.0000000000000000 120.0000000000000000)',
kml='<MultiGeometry><Point><coordinates>10.0,80.0,0</coordinates></Point><Point><coordinates>110.0,170.0,0</coordinates></Point><Point><coordinates>110.0,120.0,0</coordinates></Point></MultiGeometry>',
gml='<gml:MultiPoint><gml:pointMember><gml:Point><gml:coordinates>10,80</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>110,170</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>110,120</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint>'),
+ TestGeom('MULTILINESTRING ((110 100,40 30,180 30),(170 30,110 90,50
30))', ewkt='MULTILINESTRING ((110.0000000000000000 100.0000000000000000,
40.0000000000000000 30.0000000000000000, 180.0000000000000000
30.0000000000000000), (170.0000000000000000 30.0000000000000000,
110.0000000000000000 90.0000000000000000, 50.0000000000000000
30.0000000000000000))',
kml='<MultiGeometry><LineString><coordinates>110.0,100.0,0 40.0,30.0,0
180.0,30.0,0</coordinates></LineString><LineString><coordinates>170.0,30.0,0
110.0,90.0,0 50.0,30.0,0</coordinates></LineString></MultiGeometry>',
gml='<gml:MultiLineString><gml:lineStringMember><gml:LineString><gml:coordinates>110,100
40,30
180,30</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates>170,30
110,90
50,30</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString>'),
+ TestGeom('MULTIPOLYGON (((110 110,70 200,150 200,110 110),(110
110,100 180,120 180,110 110)),((110 110,150 20,70 20,110 110),(110 110,120
40,100 40,110 110)))', ewkt='MULTIPOLYGON (((110.0000000000000000
110.0000000000000000, 70.0000000000000000 200.0000000000000000,
150.0000000000000000 200.0000000000000000, 110.0000000000000000
110.0000000000000000), (110.0000000000000000 110.0000000000000000,
100.0000000000000000 180.0000000000000000, 120.0000000000000000
180.0000000000000000, 110.0000000000000000 110.0000000000000000)),
((110.0000000000000000 110.0000000000000000, 150.0000000000000000
20.0000000000000000, 70.0000000000000000 20.0000000000000000,
110.0000000000000000 110.0000000000000000), (110.0000000000000000
110.0000000000000000, 120.0000000000000000 40.0000000000000000,
100.0000000000000000 40.0000000000000000, 110.0000000000000000
110.0000000000000000)))',
kml='<MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>110.0,110.0,0
70.0,200.0,0 150.0,200.0,0
110.0,110.0,0</coordinates></LinearRing></outerBoundaryIs><innerBoundaryIs><LinearRing><coordinates>110.0,110.0,0
100.0,180.0,0 120.0,180.0,0
110.0,110.0,0</coordinates></LinearRing></innerBoundaryIs></Polygon><Polygon><outerBoundaryIs><LinearRing><coordinates>110.0,110.0,0
150.0,20.0,0 70.0,20.0,0
110.0,110.0,0</coordinates></LinearRing></outerBoundaryIs><innerBoundaryIs><LinearRing><coordinates>110.0,110.0,0
120.0,40.0,0 100.0,40.0,0
110.0,110.0,0</coordinates></LinearRing></innerBoundaryIs></Polygon></MultiGeometry>',
gml='<gml:MultiPolygon><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>110,110
70,200 150,200
110,110</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>110,110
100,180 120,180
110,110</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>110,110
150,20 70,20
110,110</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>110,110
120,40 100,40
110,110</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon>'),
+ TestGeom('GEOMETRYCOLLECTION (POINT (110 260),LINESTRING (110 0,110
60))', ewkt='GEOMETRYCOLLECTION (POINT (110.0000000000000000
260.0000000000000000), LINESTRING (110.0000000000000000 0.0000000000000000,
110.0000000000000000 60.0000000000000000))',
kml='<MultiGeometry><Point><coordinates>110.0,260.0,0</coordinates></Point><LineString><coordinates>110.0,0.0,0
110.0,60.0,0</coordinates></LineString></MultiGeometry>',
gml='<gml:GeometryCollection><gml:geometryMember><gml:Point><gml:coordinates>110,260</gml:coordinates></gml:Point></gml:geometryMember><gml:geometryMember><gml:LineString><gml:coordinates>110,0
110,60</gml:coordinates></gml:LineString></gml:geometryMember></gml:GeometryCollection>'),
)
# Errors
Modified: django/branches/gis/django/contrib/gis/tests/test_gdal_geom.py
===================================================================
--- django/branches/gis/django/contrib/gis/tests/test_gdal_geom.py
2007-09-30 04:19:31 UTC (rev 6439)
+++ django/branches/gis/django/contrib/gis/tests/test_gdal_geom.py
2007-09-30 15:16:22 UTC (rev 6440)
@@ -30,11 +30,18 @@
self.assertEqual(False, OGRGeomType('point') == 2)
self.assertEqual(True, OGRGeomType(6) == 'MULtiPolyGON')
- def test01_wkt(self):
+ def test01a_wkt(self):
"Testing WKT output."
for g in wkt_out:
geom = OGRGeometry(g.wkt)
+ self.assertEqual(g.wkt, geom.wkt)
+ def test01b_gml(self):
+ "Testing GML output."
+ for g in wkt_out:
+ geom = OGRGeometry(g.wkt)
+ self.assertEqual(g.gml, geom.gml)
+
def test02_points(self):
"Testing Point objects."
@@ -140,7 +147,6 @@
self.assertEqual(sr.wkt, poly.srs.wkt)
for ring in poly:
self.assertEqual(sr.wkt, ring.srs.wkt)
-
def suite():
s = unittest.TestSuite()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---