[GRASS-SVN] r39378 - in grass/trunk: include lib/vector/Vlib
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Oct 2 16:56:52 EDT 2009
Author: martinl
Date: 2009-10-02 16:56:51 -0400 (Fri, 02 Oct 2009)
New Revision: 39378
Modified:
grass/trunk/include/vector.h
grass/trunk/lib/vector/Vlib/ascii.c
grass/trunk/lib/vector/Vlib/simple_features.c
Log:
Simple Features API: Vect_sfa_is_line_closed() added
Modified: grass/trunk/include/vector.h
===================================================================
--- grass/trunk/include/vector.h 2009-10-02 19:27:49 UTC (rev 39377)
+++ grass/trunk/include/vector.h 2009-10-02 20:56:51 UTC (rev 39378)
@@ -419,6 +419,7 @@
void Vect_sfa_write_line_wkt(const struct line_pnts *, int, int, int, FILE *);
int Vect_sfa_check_line_type(const struct line_pnts *, int, int, int);
int Vect_sfa_get_line_type(const struct line_pnts *, int, int);
+int Vect_sfa_is_line_closed(const struct line_pnts *, int, int);
/*
* Internal functions, MUST NOT be used in modules
Modified: grass/trunk/lib/vector/Vlib/ascii.c
===================================================================
--- grass/trunk/lib/vector/Vlib/ascii.c 2009-10-02 19:27:49 UTC (rev 39377)
+++ grass/trunk/lib/vector/Vlib/ascii.c 2009-10-02 20:56:51 UTC (rev 39378)
@@ -11,6 +11,7 @@
(>=v2). Read the file COPYING that comes with GRASS for details.
\author Original author CERL
+ \author Updated for GRASS 7 (SF support) by Martin Landa <landa.martin gmail.com>
*/
#include <stdio.h>
Modified: grass/trunk/lib/vector/Vlib/simple_features.c
===================================================================
--- grass/trunk/lib/vector/Vlib/simple_features.c 2009-10-02 19:27:49 UTC (rev 39377)
+++ grass/trunk/lib/vector/Vlib/simple_features.c 2009-10-02 20:56:51 UTC (rev 39378)
@@ -119,6 +119,34 @@
fflush(file);
}
+/*!
+ \brief Check if feature is closed
+
+ \param Points pointer to line_pnts structure
+ \param type feature type (GV_POINT, GV_LINE, ...)
+
+ \return 1 feature closed
+ \return 0 feature not closed
+ \return -1 feature type not supported (GV_POINT, GV_CENTROID, ...)
+*/
+int Vect_sfa_is_line_closed(const struct line_pnts *Points, int type, int with_z)
+{
+ int npoints;
+ if (type & (GV_LINES)) {
+ npoints = Vect_get_num_line_points(Points);
+ if (npoints > 2 &&
+ Points->x[0] == Points->x[npoints-1] &&
+ Points->y[0] == Points->y[npoints-1]) {
+ if (!with_z)
+ return 1;
+ if (Points->z[0] == Points->z[npoints-1])
+ return 1;
+ }
+ return 0;
+ }
+ return -1;
+}
+
int check_sftype(const struct line_pnts *points, int type, int sftype, int with_z)
{
if (type == GV_POINT && sftype == SF_POINT) {
@@ -133,26 +161,15 @@
return 1;
}
if (sftype == SF_LINEARRING) {
- int num = Vect_get_num_line_points(points);
- if (points->x[0] == points->x[num-1] &&
- points->y[0] == points->y[num-1]) {
- if (!with_z) {
- return 1;
- }
- else if (points->z[0] == points->z[num-1]) {
- return 1;
- }
- }
+ if (Vect_sfa_is_line_closed(points, type, with_z))
+ return 1;
}
}
if (type == GV_BOUNDARY) {
- int num = Vect_get_num_line_points(points);
if (sftype == SF_POLYGON &&
- points->x[0] == points->x[num-1] &&
- points->y[0] == points->y[num-1]) {
+ Vect_sfa_is_line_closed(points, type, 0)) /* force 2D */
return 1;
- }
}
return 0;
More information about the grass-commit
mailing list