[postgis-devel] [PostGIS] #885: pgsql2shp fields conversion from predefined list
PostGIS
trac at osgeo.org
Sat Mar 26 16:27:35 PDT 2011
#885: pgsql2shp fields conversion from predefined list
-------------------------+--------------------------------------------------
Reporter: rodo | Owner: loic
Type: enhancement | Status: new
Priority: medium | Milestone: PostGIS 1.5.3
Component: postgis | Version: 1.5.X
Keywords: |
-------------------------+--------------------------------------------------
Comment(by loic):
Here is a tentative patch against 1.5, which does not even compile yet.
And I'm still unsure where the unit tests should be written.
{{{
--- pgsql2shp.c.~1~ 2011-03-26 17:41:44.000000000 +0100
+++ pgsql2shp.c 2011-03-27 00:19:35.700567533 +0100
@@ -65,6 +65,8 @@
int rowbuflen;
char temptablename[256];
char *geo_col_name, *table, *shp_file, *schema, *usrquery;
+char **geo_map = 0;
+int geo_map_size = 0;
int type_ary[256];
char *main_scan_query;
DBFHandle dbf;
@@ -1258,6 +1260,52 @@
return 0;
}
+#include <sys/stat.h>
+
+void
+read_geo_map(char* file)
+{
+#if 0
+ struct stat stat_buf;
+ static char* content = 0;
+ {
+ FILE* fp = 0;
+ if(stat(file, &stat_buf) < 0) {
+ perror(file);
+ return;
+ }
+ content = malloc(stat_buf.st_size);
+ fp = fopen(file, 'r');
+ if(stat_buf.st_size != fread(content, stat_buf.st_size, 1, fp)) {
+ free(content);
+ fprintf(stderr, "fread did not return the expected amount of
chars");
+ }
+ fclose(fp);
+ }
+ {
+ int i;
+ geo_map_size = 0;
+
+ for(i = 0; i < stat_buf.st_size; i++) {
+ if(content[i] == '\n') {
+ geo_map_size++;
+ }
+ }
+ geo_map = (char**)malloc(sizeof(char*)*geo_map_size);
+ {
+ char** map = geo_map;
+ *map++ = content;
+ for(i = 0; i < stat_buf.st_size; i++) {
+ if(content[i] == '\n' && i + 1 < stat_buf.st_size)
+ *map++ = content + 1;
+ if(content[i] == '\n' || content[i] == ' ')
+ content[i] = '\0';
+ }
+ }
+ }
+#endif
+}
+
void
usage(char* me, int status, FILE* out)
{
@@ -1299,7 +1347,7 @@
memset(buf, 0, 2048); /* just in case... */
/* Parse command line */
- while ((c = pgis_getopt(ARGC, ARGV, "bf:h:du:p:P:g:rk")) != EOF)
+ while ((c = pgis_getopt(ARGC, ARGV, "bf:h:du:p:P:g:rkm:")) != EOF)
{
switch (c)
{
@@ -1332,6 +1380,9 @@
case 'g':
geo_col_name = pgis_optarg;
break;
+ case 'm':
+ read_geo_map(pgis_optarg);
+ break;
case 'k':
keep_fieldname_case = 1;
break;
@@ -1594,9 +1645,19 @@
* becomes __xmin when escaped
*/
- /* Limit dbf field name to 10-digits */
- strncpy(field_name, ptr, 10);
- field_name[10] = 0;
+ if(geo_map) {
+ int i;
+ for(i=0; i<geo_map_size; i++) {
+ if(!strcasecmp(geo_map, ptr)) {
+ /* the replacement follows the terminating null */
+ strcpy(field_name, geo_map + strlen(geo_map) + 1);
+ }
+ }
+ } else {
+ /* Limit dbf field name to 10-digits */
+ strncpy(field_name, ptr, 10);
+ field_name[10] = 0;
+ }
/*
* make sure the fields all have unique names,
}}}
--
Ticket URL: <http://trac.osgeo.org/postgis/ticket/885#comment:3>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-devel
mailing list