소스 검색

vector library and pygrass rpc: Fixed bug in vector line to wkb conversion

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@67063 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 9 년 전
부모
커밋
350a60a3d5
3개의 변경된 파일20개의 추가작업 그리고 11개의 파일을 삭제
  1. 1 1
      include/defs/vector.h
  2. 9 3
      lib/python/pygrass/vector/__init__.py
  3. 10 7
      lib/vector/Vlib/geos_to_wktb.c

+ 1 - 1
include/defs/vector.h

@@ -611,7 +611,7 @@ unsigned char *Vect_read_area_to_wkb(struct Map_info *, int, size_t *);
 unsigned char *Vect_read_line_to_wkb(const struct Map_info *, 
                                      struct line_pnts *, 
                                      struct line_cats *, 
-                                     int line, size_t *);
+                                     int, size_t *, int *);
 #endif
 
     /* Raster color tables */

+ 9 - 3
lib/python/pygrass/vector/__init__.py

@@ -714,7 +714,6 @@ class VectorTopo(Vector):
 
             >>> test_vect.close()
 
-
         """
 
         supported = ['point', 'line', 'boundary', 'centroid']
@@ -737,14 +736,21 @@ class VectorTopo(Vector):
             line_c = libvect.line_cats()
             size = ctypes.c_size_t()
             cat = ctypes.c_int()
+            error = ctypes.c_int()
 
             for f_id in bboxlist.ids:
                 barray = libvect.Vect_read_line_to_wkb(self.c_mapinfo,
                                                        ctypes.byref(line_p),
                                                        ctypes.byref(line_c),
-                                                       f_id, ctypes.byref(size))
+                                                       f_id,
+                                                       ctypes.byref(size),
+                                                       ctypes.byref(error))
                 if not barray:
-                    raise GrassError(_("Unable to read line of feature %i"%(f_id)))
+                    if error == -1:
+                        raise GrassError(_("Unable to read line of feature %i"%(f_id)))
+                    if error == -2:
+                        print("Empty feature %i"%(f_id))
+                    continue
 
                 ok = libvect.Vect_cat_get(ctypes.byref(line_c), field,
                                           ctypes.byref(cat))

+ 10 - 7
lib/vector/Vlib/geos_to_wktb.c

@@ -125,7 +125,8 @@ char *Vect_read_area_to_wkt(struct Map_info * Map, int area)
 unsigned char *Vect_read_line_to_wkb(const struct Map_info *Map, 
                                      struct line_pnts *line_p, 
                                      struct line_cats *line_c, 
-                                     int line, size_t *size)
+                                     int line, size_t *size,
+                                     int *error)
 {    
     static int init = 0;
     /* The writer is static for performance reasons */
@@ -150,6 +151,8 @@ unsigned char *Vect_read_line_to_wkb(const struct Map_info *Map,
     }
     
     int f_type = Vect_read_line(Map, line_p, line_c, line);
+    /* Save the error state */
+    *error = f_type;
     
     if(f_type < 0)
         return(NULL);
@@ -157,6 +160,12 @@ unsigned char *Vect_read_line_to_wkb(const struct Map_info *Map,
     GEOSWKBWriter_setOutputDimension(writer, Vect_is_3d(Map) ? 3 : 2);
 
     GEOSGeometry *geom = Vect_line_to_geos(line_p, f_type, Vect_is_3d(Map));
+    
+    if(destroy_cats == 1)
+        Vect_destroy_cats_struct(line_c);
+
+    if(destroy_line == 1)
+        Vect_destroy_line_struct(line_p);
 
     if(!geom) {
         return(NULL);
@@ -165,12 +174,6 @@ unsigned char *Vect_read_line_to_wkb(const struct Map_info *Map,
     wkb = GEOSWKBWriter_write(writer, geom, size);
 
     GEOSGeom_destroy(geom);
-    
-    if(destroy_cats == 1)
-        Vect_destroy_cats_struct(line_c);
-
-    if(destroy_line == 1)
-        Vect_destroy_line_struct(line_p);
 
     return(wkb);
 }