[GRASS-SVN] r51082 - in grass/trunk: include/defs lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Mar 16 12:11:32 EDT 2012


Author: martinl
Date: 2012-03-16 09:11:32 -0700 (Fri, 16 Mar 2012)
New Revision: 51082

Modified:
   grass/trunk/include/defs/vector.h
   grass/trunk/lib/vector/Vlib/build.c
   grass/trunk/lib/vector/Vlib/build_ogr.c
   grass/trunk/lib/vector/Vlib/build_sfa.c
   grass/trunk/lib/vector/Vlib/read_pg.c
   grass/trunk/lib/vector/Vlib/write_ogr.c
   grass/trunk/lib/vector/Vlib/write_pg.c
   grass/trunk/lib/vector/Vlib/write_sfa.c
Log:
vlib(pg): skip features without geometry
	  fix offset for multi-features
	  implement Vect_fidx_dump()


Modified: grass/trunk/include/defs/vector.h
===================================================================
--- grass/trunk/include/defs/vector.h	2012-03-16 15:54:14 UTC (rev 51081)
+++ grass/trunk/include/defs/vector.h	2012-03-16 16:11:32 UTC (rev 51082)
@@ -464,6 +464,7 @@
 int Vect_build_sidx(struct Map_info *);
 int Vect_open_fidx(struct Map_info *, struct Format_info_offset *);
 int Vect_save_fidx(struct Map_info *, struct Format_info_offset *);
+int Vect_fidx_dump(struct Map_info *, FILE *);
 
 int Vect__write_head(const struct Map_info *);
 int Vect__read_head(struct Map_info *);

Modified: grass/trunk/lib/vector/Vlib/build.c
===================================================================
--- grass/trunk/lib/vector/Vlib/build.c	2012-03-16 15:54:14 UTC (rev 51081)
+++ grass/trunk/lib/vector/Vlib/build.c	2012-03-16 16:11:32 UTC (rev 51082)
@@ -1121,7 +1121,7 @@
    \return 1 on success
    \return 0 on error
  */
-int Vect_sidx_dump(struct Map_info *Map, FILE * out)
+int Vect_sidx_dump(const struct Map_info *Map, FILE * out)
 {
     if (!(Map->plus.Spidx_built)) {
 	Vect_build_sidx_from_topo(Map);

Modified: grass/trunk/lib/vector/Vlib/build_ogr.c
===================================================================
--- grass/trunk/lib/vector/Vlib/build_ogr.c	2012-03-16 15:54:14 UTC (rev 51081)
+++ grass/trunk/lib/vector/Vlib/build_ogr.c	2012-03-16 16:11:32 UTC (rev 51082)
@@ -84,9 +84,10 @@
 	return 0;
     }
 
-    G_message(_("Using external data format '%s' (feature type '%s')"),
-	      Vect_get_finfo_format_info(Map),
-	      Vect_get_finfo_geometry_type(Map));
+    if (build > GV_BUILD_NONE)
+	G_message(_("Using external data format '%s' (feature type '%s')"),
+		  Vect_get_finfo_format_info(Map),
+		  Vect_get_finfo_geometry_type(Map));
     
     return Vect__build_sfa(Map, build);
 #else

Modified: grass/trunk/lib/vector/Vlib/build_sfa.c
===================================================================
--- grass/trunk/lib/vector/Vlib/build_sfa.c	2012-03-16 15:54:14 UTC (rev 51081)
+++ grass/trunk/lib/vector/Vlib/build_sfa.c	2012-03-16 16:11:32 UTC (rev 51082)
@@ -350,9 +350,13 @@
 	wkb_data = PQgetvalue(pg_info->res, iFeature, 1);
 	
 	/* cache feature (lines) */
-	cache_feature(wkb_data,
-		      FALSE, &(pg_info->cache), &fparts);
-
+	if (SF_NONE == cache_feature(wkb_data,
+				     FALSE, &(pg_info->cache), &fparts)) {
+	    G_warning(_("Feature %d without geometry skipped"),
+		      iFeature + 1);
+	    continue;
+	}
+	
 	/* register topo */
 	reset_parts(&parts);
 	add_part(&parts, fid);
@@ -364,10 +368,12 @@
 	    
 	    G_debug(4, "Feature: fid = %d part = %d", fid, ipart);
 	    
-	    add_part(&parts, ipart);
+	    if (fparts.n_parts > 1)
+		add_part(&parts, ipart);
 	    add_geometry_pg(&(Map->plus), pg_info, &fparts, ipart,
 			    fid, build, &parts);
-	    del_part(&parts);
+	    if (fparts.n_parts > 1)
+		del_part(&parts);
 	}
     }
 
@@ -738,3 +744,42 @@
     
     return 1;
 }
+
+/*!
+   \brief Dump feature index to file
+
+   \param Map pointer to Map_info struct
+   \param out file for output (stdout/stderr for example)
+
+   \return 1 on success
+   \return 0 on error
+ */
+int Vect_fidx_dump(const struct Map_info *Map, FILE *out)
+{
+    int i;
+    const struct Format_info_offset *offset;
+
+    if (Map->format != GV_FORMAT_OGR &&
+	Map->format != GV_FORMAT_POSTGIS) {
+	G_warning(_("Feature index is built only for non-native formats. "
+		    "Nothing to dump."));
+	return 0;
+    }
+
+    if (Map->format == GV_FORMAT_OGR)
+	offset = &(Map->fInfo.ogr.offset);
+    else
+	offset = &(Map->fInfo.pg.offset);
+    
+    fprintf(out, "---------- FEATURE INDEX DUMP ----------\n");
+    
+    fprintf(out, "feature type: %s\n", 
+	    Vect_get_finfo_geometry_type(Map));
+    fprintf(out, "number of features: %d\n\noffset array:\n",
+	    Vect_get_num_lines(Map));
+    for (i = 0; i < offset->array_num; i++) {
+	fprintf(out, "%5d : %d\n", i, offset->array[i]);
+    }
+
+    return 1;
+}

Modified: grass/trunk/lib/vector/Vlib/read_pg.c
===================================================================
--- grass/trunk/lib/vector/Vlib/read_pg.c	2012-03-16 15:54:14 UTC (rev 51081)
+++ grass/trunk/lib/vector/Vlib/read_pg.c	2012-03-16 16:11:32 UTC (rev 51082)
@@ -239,14 +239,22 @@
     /* read feature to cache if necessary */
     if (pg_info->cache.fid != fid) {
 	G_debug(4, "read feature (fid = %ld) to cache", fid);
-	sf_type = (int) get_feature(pg_info, fid);
+	sf_type = get_feature(pg_info, fid);
 	
-	if ((int) sf_type < 0)
+	if (sf_type == SF_NONE) {
+	    G_warning(_("Feature %d without geometry skipped"), fid);
+	    return -1;
+	}
+
+	if ((int) sf_type < 0) /* -1 || - 2 */
 	    return (int) sf_type;
     }
 
     /* get data from cache */
-    ipart = pg_info->offset.array[offset + 1];
+    if (sf_type == SF_POINT || sf_type == SF_LINESTRING)
+	ipart = 0;
+    else 
+	ipart = pg_info->offset.array[offset + 1];
     type  = pg_info->cache.lines_types[ipart];
     G_debug(4, "read feature part: %d -> type = %d",
 	    ipart, type);    
@@ -318,6 +326,12 @@
 	    /* cache feature -> line_p & line_c */
 	    sf_type = get_feature(pg_info, -1);
 	    
+	    if (sf_type == SF_NONE) {
+		G_warning(_("Feature %d without geometry skipped"),
+			  Map->next_line);
+		return -1;
+	    }
+
 	    if ((int) sf_type < 0) /* -1 || - 2 */
 		return (int) sf_type;
 
@@ -562,9 +576,16 @@
     wkb_data  = hex_to_wkb(data, &nbytes);
     
     if (nbytes < 5) {
-	G_warning(_("Invalid WKB content: %d bytes"), nbytes);
 	G_free(wkb_data);
-	return SF_UNKNOWN;
+	if (nbytes > 0) {
+	    G_debug(3, "cache_feature(): invalid geometry");
+	    G_warning(_("Invalid WKB content: %d bytes"), nbytes);
+	    return SF_UNKNOWN;
+	}
+	else {
+	    G_debug(3, "cache_feature(): no geometry");
+	    return SF_NONE;
+	}
     }
     
     /* parsing M coordinate not supported */
@@ -611,7 +632,7 @@
         ftype = (SF_FeatureType) wkb_data[4];
 	is3D = wkb_data[1] & 0x80 || wkb_data[3] & 0x80;
     }
-    G_debug(5, "cache_feature(): sf_type = %d", ftype);
+    G_debug(3, "cache_feature(): sf_type = %d", ftype);
    
     /* allocate space in lines cache - be minimalistic
        

Modified: grass/trunk/lib/vector/Vlib/write_ogr.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write_ogr.c	2012-03-16 15:54:14 UTC (rev 51081)
+++ grass/trunk/lib/vector/Vlib/write_ogr.c	2012-03-16 16:11:32 UTC (rev 51082)
@@ -195,7 +195,8 @@
     if (ret != OGRERR_NONE)
 	return -1;
     
-    G_debug(3, "V1_write_line_ogr(): -> offset = %lu", (unsigned long) offset);
+    G_debug(3, "V1_write_line_ogr(): -> offset = %lu offset_num = %d cat = %d",
+	    (unsigned long) offset, offset_info->array_num, cat);
 
     return offset;
 #else

Modified: grass/trunk/lib/vector/Vlib/write_pg.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write_pg.c	2012-03-16 15:54:14 UTC (rev 51081)
+++ grass/trunk/lib/vector/Vlib/write_pg.c	2012-03-16 16:11:32 UTC (rev 51082)
@@ -171,13 +171,13 @@
 
     offset = offset_info->array_num;
     
-    offset_info->array[offset_info->array_num++] = (int) cat;
+    offset_info->array[offset_info->array_num++] = cat;
     if (sf_type == SF_POLYGON || sf_type == SF_POLYGON25D) {
-	/* register exterior ring in offset array */
+	/* register first part in offset array */
 	offset_info->array[offset_info->array_num++] = 0; 
     }
-    
-    G_debug(3, "V1_write_line_ogr(): -> offset = %lu", (unsigned long) offset);
+    G_debug(3, "V1_write_line_pg(): -> offset = %lu offset_num = %d cat = %d",
+	    (unsigned long) offset, offset_info->array_num, cat);
 
     return offset;
 #else

Modified: grass/trunk/lib/vector/Vlib/write_sfa.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write_sfa.c	2012-03-16 15:54:14 UTC (rev 51081)
+++ grass/trunk/lib/vector/Vlib/write_sfa.c	2012-03-16 16:11:32 UTC (rev 51082)
@@ -265,7 +265,7 @@
     
     struct bound_box box, abox;
     
-    G_debug(3, "V2__add_line_to_topo_ogr(): line = %d npoints = %d", line,
+    G_debug(3, "V2__add_line_to_topo_sfa(): line = %d npoints = %d", line,
 	    points->n_points);
 
     plus = &(Map->plus);



More information about the grass-commit mailing list