[GRASS-SVN] r56345 - grass-addons/grass6/vector/v.in.gshhs
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue May 21 04:57:42 PDT 2013
Author: mmetz
Date: 2013-05-21 04:57:42 -0700 (Tue, 21 May 2013)
New Revision: 56345
Modified:
grass-addons/grass6/vector/v.in.gshhs/gshhs.h
grass-addons/grass6/vector/v.in.gshhs/main.c
Log:
v.in.gshhs: support data release 9
Modified: grass-addons/grass6/vector/v.in.gshhs/gshhs.h
===================================================================
--- grass-addons/grass6/vector/v.in.gshhs/gshhs.h 2013-05-21 11:05:24 UTC (rev 56344)
+++ grass-addons/grass6/vector/v.in.gshhs/gshhs.h 2013-05-21 11:57:42 UTC (rev 56345)
@@ -1,11 +1,11 @@
-/* $Id: gshhs.h,v 1.31 2010/07/18 03:16:01 guru Exp $
+/* $Id: gshhs.h,v 1.17 2008/01/23 03:22:49 guru Exp $
*
* Include file defining structures used in gshhs.c
*
* Paul Wessel, SOEST
*
- * Copyright (c) 1996-2010 by P. Wessel and W. H. F. Smith
- * See LICENSE.TXT file for copying and redistribution conditions.
+ * Copyright (c) 1996-2008 by P. Wessel and W. H. F. Smith
+ * See COPYING file for copying and redistribution conditions.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,12 +27,9 @@
* 28-AUG-2007. PW: Version 1.6. no format change
* For use with version 1.6 of GSHHS which now has WDBII
* borders and rivers.
- * 03-JUL-2008. PW: Version 1.11. New -I<id> option to pull out a single pol
- * 27-MAY-2009. PW: Version 1.12. Now includes container polygon ID in header,
- * an ancestor ID, and area of the reduced polygon. Works on
- * GSHHS 2.0 data.
- * Header is now 44 bytes (all 4-byte integers)
- * 24-MAY-2010. PW: Data version is now 2.1.0. [no change to format]
+ *
+ * may need updating for new GSHHS versions
+ *
*/
#ifndef _GSHHS
@@ -41,13 +38,8 @@
#include <stdio.h>
#include <stdlib.h>
-#include <ctype.h>
#include <math.h>
-#ifdef WIN32
-#pragma warning( disable : 4996 )
-#endif
-
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
@@ -56,35 +48,52 @@
#define SEEK_CUR 1
#endif
-#define GSHHS_DATA_RELEASE 8 /* For v2.1.0 data set */
-#define GSHHS_DATA_VERSION "2.1.0" /* For v2.1.0 data set */
-#define GSHHS_PROG_VERSION "1.12"
+#define GSHHS_DATA_RELEASE 9 /* For v2.2.0 data set */
+#define GSHHS_DATA_VERSION "2.2.0" /* For v2.2.0 data set */
+#define GSHHS_PROG_VERSION "1.13"
-#define GSHHS_SCL 1.0e-6 /* Convert micro-degrees to degrees */
+#define GSHHS_SCL 1.0e-6 /* COnvert micro-degrees to degrees */
/* For byte swapping on little-endian systems (GSHHS is defined to be bigendian) */
#define swabi4(i4) (((i4) >> 24) + (((i4) >> 8) & 65280) + (((i4) & 65280) << 8) + (((i4) & 255) << 24))
-struct GSHHS { /* Global Self-consistent Hierarchical High-resolution Shorelines */
+struct GSHHS1 { /* Global Self-consistent Hierarchical High-resolution Shorelines */
+ int id; /* Unique polygon id number, starting at 0 */
+ int n; /* Number of points in this polygon */
+ int flag; /* = level + version << 8 + greenwich << 16 + source << 24 */
+ /* flag contains 4 items, one in each byte, as follows:
+ * low byte: level = flag & 255: Values: 1 land, 2 lake, 3 island_in_lake, 4 pond_in_island_in_lake
+ * 2nd byte: version = (flag >> 8) & 255: Values: Should be 4 for GSHHS version 1.4
+ * 3rd byte: greenwich = (flag >> 16) & 255: Values: Greenwich is 1 if Greenwich is crossed
+ * 4th byte: source = (flag >> 24) & 255: Values: 0 = CIA WDBII, 1 = WVS
+ */
+ int west, east, south, north; /* min/max extent in micro-degrees */
+ int area; /* Area of polygon in 1/10 km^2 */
+};
+
+struct GSHHS2 { /* Global Self-consistent Hierarchical High-resolution Shorelines */
int id; /* Unique polygon id number, starting at 0 */
int n; /* Number of points in this polygon */
- int flag; /* = level + version << 8 + greenwich << 16 + source << 24 + river << 25 */
- /* flag contains 5 items, as follows:
+ int flag; /* = level + version << 8 + greenwich << 16 + source << 24 + river << 25 + p << 26 */
+ /* flag contains 6 items, as follows:
* low byte: level = flag & 255: Values: 1 land, 2 lake, 3 island_in_lake, 4 pond_in_island_in_lake
- * 2nd byte: version = (flag >> 8) & 255: Values: Should be 7 for GSHHS release 7
- * 3rd byte: greenwich = (flag >> 16) & 1: Values: Greenwich is 1 if Greenwich is crossed
+ * 2nd byte: version = (flag >> 8) & 255: Values: Should be 9 for GSHHS release 9
+ * 3rd byte: greenwich = (flag >> 16) & 3: Values: 0 if Greenwich nor Dateline are crossed,
+ * 1 if Greenwich is crossed, 2 if Dateline is crossed, 3 if both is crossed.
* 4th byte: source = (flag >> 24) & 1: Values: 0 = CIA WDBII, 1 = WVS
- * 4th byte: river = (flag >> 25) & 1: Values: 0 = not set, 1 = river-lake and level = 2
+ * 4th byte: river = (flag >> 25) & 1: Values: 0 = not set, 1 = river-lake and GSHHS level = 2 (or WDBII level 0)
+ * new in GSHHS_DATA_VERSION 2.2:
+ * 4th byte: area magnitude scale p (as in 10^p) = flag >> 26. We divide area by 10^p.
*/
int west, east, south, north; /* min/max extent in micro-degrees */
- int area; /* Area of polygon in 1/10 km^2 */
- int area_full; /* Area of original full-resolution polygon in 1/10 km^2 */
+ int area; /* Area of polygon in km^2 * 10^p for this resolution file */
+ int area_full; /* Area of corresponding full-resolution polygon in km^2 * 10^p */
int container; /* Id of container polygon that encloses this polygon (-1 if none) */
int ancestor; /* Id of ancestor polygon in the full resolution set that was the source of this polygon (-1 if none) */
};
-struct GSHHS_POINT { /* Each lon, lat pair is stored in micro-degrees in 4-byte integer format */
+struct GSHHS_POINT { /* Each lon, lat pair is stored in micro-degrees in 4-byte integer format */
int x;
int y;
};
Modified: grass-addons/grass6/vector/v.in.gshhs/main.c
===================================================================
--- grass-addons/grass6/vector/v.in.gshhs/main.c 2013-05-21 11:05:24 UTC (rev 56344)
+++ grass-addons/grass6/vector/v.in.gshhs/main.c 2013-05-21 11:57:42 UTC (rev 56345)
@@ -1,3 +1,4 @@
+
/**********************************************************************
*
* MODULE: v.in.gshhs (based on gshhstograss.c)
@@ -35,7 +36,6 @@
/* updating to a newer GSHHS version can be as easy as replacing
* struct GSHHS2 und updating GSHHS_DATA_RELEASE in gshhs.h
* if not too many changes were introduced */
-/* TODO 9/2010: GSHHS1 and GSHHS2 have been unified in gshhs.h, simplify code here */
#include "gshhs.h"
/* GSHHS version 1.x import */
@@ -48,7 +48,21 @@
struct pj_info info_in;
struct pj_info info_out;
+/* For byte swapping on little-endian systems (GSHHS is defined to be bigendian) */
+static int do_flip(void)
+{
+ int itest = 0x01020304;
+
+ /* yes, this is quick and dirty */
+ if (((unsigned char *)&itest)[0] == (unsigned char)0x01) {
+ G_debug(1, "big endian");
+ return 0;
+ }
+
+ return 1;
+}
+
int main(int argc, char **argv)
{
double minx = -180., maxx = 180., miny = -90., maxy = 90.;
@@ -61,7 +75,7 @@
FILE *fp;
int i, n_read, flip, version;
int cnt = 0;
- struct GSHHS h;
+ struct GSHHS1 h;
/* GRASS specific */
struct Key_Value *out_proj_keys, *out_unit_keys;
int zone;
@@ -248,29 +262,30 @@
/* open GSHHS shoreline for reading */
if ((fp = fopen(dataname, "rb")) == NULL) {
- G_fatal_error(_("Unable to open input file <%s>"), dataname);
+ G_fatal_error(_("Could not find file <%s>"), dataname);
}
/* Open new vector */
if (0 > Vect_open_new(&Map, outname, 0)) {
- G_fatal_error(_("Unable to create vector map <%s>"), outname);
+ G_fatal_error(_("Cannot open new vector map <%s>"), outname);
}
/* read header from GSHHS database */
- n_read = fread((void *)&h, (size_t) sizeof(struct GSHHS), (size_t) 1, fp);
+ n_read = fread((void *)&h, (size_t) sizeof(struct GSHHS1), (size_t) 1, fp);
version = (h.flag >> 8) & 255;
+ G_debug(1, "GSHHS data release: %d", version);
- /* Take as sign that byte-swapping is needed */
- /* if version < 2, source is read */
- flip = (version < 2);
+ /* test if byte-swapping is needed */
+ flip = do_flip();
if (flip) {
version = swabi4((unsigned int)h.flag);
version = (version >> 8) & 255;
}
+ G_debug(0, "GSHHS data release: %d", version);
- /* check version support (GSHHS_DATA_RELEASE is defined in gshhs.h)*/
+ /* check version support */
if (version < 4) /* not sure if that check works... */
- G_fatal_error("Trying to import version %d, only GSHHS versions 4 to %d (2.0) are supported.", version, (int)GSHHS_DATA_RELEASE);
+ G_fatal_error("Trying to import version %d, only GSHHS versions 4 to %d (2.2) are supported.", version, (int)GSHHS_DATA_RELEASE);
if (version > GSHHS_DATA_RELEASE)
G_fatal_error("Import of version %d not yet supported, highest supported version is GSHHS version 7 (2.0).", version);
@@ -378,7 +393,7 @@
int max_east = 180000000; /* max_east = 270000000: confuses GRASS */
int cnt = 0, getme = 0;
struct GSHHS_POINT p; /* renamed to avoid conflict */
- struct GSHHS h;
+ struct GSHHS1 h;
/* GRASS specific */
int type;
struct line_pnts *Points, **BPoints;
@@ -386,16 +401,16 @@
int use_bpoints, n_bpoints, bpoints_alloc = 10;
/* read header from GSHHS database */
- n_read = fread((void *)&h, (size_t) sizeof(struct GSHHS), (size_t) 1, fp);
+ n_read = fread((void *)&h, (size_t) sizeof(struct GSHHS1), (size_t) 1, fp);
version = (h.flag >> 8) & 255;
- /* Take as sign that byte-swapping is needed */
- /* if version < 2, source is read */
- flip = (version < 2);
+ /* test if byte-swapping is needed */
+ flip = do_flip();
if (flip) {
version = swabi4((unsigned int)h.flag);
version = (version >> 8) & 255;
}
+ G_debug(1, "GSHHS data release: %d", version);
/* set vector line type to GV_LINE, GV_BOUNDARY is currently not supported */
type = GV_LINE;
@@ -676,7 +691,7 @@
/* max_east = 180000000; */ /* Only Eurasiafrica needs 270 */
n_read =
- fread((void *)&h, (size_t) sizeof(struct GSHHS), (size_t) 1, fp);
+ fread((void *)&h, (size_t) sizeof(struct GSHHS1), (size_t) 1, fp);
}
Vect_destroy_line_struct(Points);
@@ -690,7 +705,6 @@
/* GSHHS version 2.x import, works with data release 7 */
/* the only difference between gshhs_import1 and gshhs_import2 is
* the use of struct GSHHS1 or struct GSHHS2, respectively */
-/* TODO 9/2010: GSHHS1 and GSHHS2 have been unified in gshhs.h, simplify code here */
int gshhs_import2(struct Map_info *Map, FILE *fp, int limit_to_region,
double minx, double maxx, double miny, double maxy)
{
@@ -701,7 +715,7 @@
int max_east = 180000000; /* max_east = 270000000: confuses GRASS */
int cnt = 0, getme = 0;
struct GSHHS_POINT p; /* renamed to avoid conflict */
- struct GSHHS h;
+ struct GSHHS2 h;
/* GRASS specific */
int type;
struct line_pnts *Points, **BPoints;
@@ -709,16 +723,16 @@
int use_bpoints, n_bpoints, bpoints_alloc = 10;
/* read header from GSHHS database */
- n_read = fread((void *)&h, (size_t) sizeof(struct GSHHS), (size_t) 1, fp);
+ n_read = fread((void *)&h, (size_t) sizeof(struct GSHHS2), (size_t) 1, fp);
version = (h.flag >> 8) & 255;
- /* Take as sign that byte-swapping is needed */
- /* if version < 2, source is read */
- flip = (version < 2);
+ /* test if byte-swapping is needed */
+ flip = do_flip();
if (flip) {
version = swabi4((unsigned int)h.flag);
version = (version >> 8) & 255;
}
+ G_debug(1, "GSHHS data release: %d", version);
/* set vector line type to GV_LINE, GV_BOUNDARY is currently not supported */
type = GV_LINE;
@@ -999,7 +1013,7 @@
/* max_east = 180000000; */ /* Only Eurasiafrica needs 270 */
n_read =
- fread((void *)&h, (size_t) sizeof(struct GSHHS), (size_t) 1, fp);
+ fread((void *)&h, (size_t) sizeof(struct GSHHS2), (size_t) 1, fp);
}
Vect_destroy_line_struct(Points);
More information about the grass-commit
mailing list