From a6b0d3d0fa56cd4d74d5cb0fd0cd6e4f8c040630 Mon Sep 17 00:00:00 2001 From: Jeff Lounsbury Date: Wed, 6 Nov 2002 23:55:44 +0000 Subject: [PATCH] added support for clockwise-ness in shp dumper git-svn-id: http://svn.osgeo.org/postgis/trunk@207 b70326c6-7e19-0410-871a-916f4a2858ee --- loader/pgsql2shp.c | 106 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 94 insertions(+), 12 deletions(-) diff --git a/loader/pgsql2shp.c b/loader/pgsql2shp.c index 028948126..4895d0cbd 100644 --- a/loader/pgsql2shp.c +++ b/loader/pgsql2shp.c @@ -25,8 +25,8 @@ int num_points(char *str); int num_lines(char *str); char *scan_to_same_level(char *str); int points_per_sublist( char *str, int *npoints, long max_lists); - - +int reverse_points(int num_points,double *x,double *y,double *z); +int is_clockwise(int num_points,double *x,double *y,double *z); //main //USAGE: pgsql2shp [] @@ -405,14 +405,14 @@ int main(int ARGC, char **ARGV){ //get what kind of Geometry type is in the table - query= (char *)malloc(strlen(table) + strlen("select distinct (geometrytype()) from where NOT geometrytype(geom) = NULL")+18); + query= (char *)malloc(strlen(table) + strlen("select distinct (geometrytype()) from where NOT geometrytype(geom) = NULL")+38); strcpy(query, "select distinct (geometrytype("); strcat(query, geo_col_name); strcat(query, ")) from ") ; strcat(query, table); strcat(query," where NOT geometrytype("); strcat(query,geo_col_name); - strcat(query,") = NULL"); + strcat(query,") IS NULL"); res3 = PQexec(conn, query); //printf("\n\n-->%s\n\n",query); @@ -1048,15 +1048,15 @@ int create_multipoints(char *str, SHPHandle shp,int dims){ if(dims == 0){ if(notnull > 0){ - obj = SHPCreateSimpleObject(SHPT_MULTIPOINT ,1,x,y,z); + obj = SHPCreateSimpleObject(SHPT_MULTIPOINT ,points,x,y,z); }else{ - obj = SHPCreateSimpleObject(SHPT_NULL ,1,x,y,z); + obj = SHPCreateSimpleObject(SHPT_NULL ,points,x,y,z); } }else{ if(notnull > 0){ - obj = SHPCreateSimpleObject(SHPT_MULTIPOINTZ ,1,x,y,z); + obj = SHPCreateSimpleObject(SHPT_MULTIPOINTZ ,points,x,y,z); }else{ - obj = SHPCreateSimpleObject(SHPT_NULL ,1,x,y,z); + obj = SHPCreateSimpleObject(SHPT_NULL ,points,x,y,z); } } @@ -1125,17 +1125,30 @@ int create_polygons(char *str,int shape_id, SHPHandle shp,int dims){ z = (double *)malloc(sizeof(double) * points[i]); notnull = parse_points(str,points[i],x,y,z); + str = scan_to_same_level(str); part_index[i] = index; + + //if this the first ring it should be clockwise, other rings are holes and should be counter-clockwise + if(i ==0){ + if(is_clockwise(points[i],x,y,z) == 0){ + reverse_points(points[i],x,y,z); + } + }else{ + if(is_clockwise(points[i],x,y,z) == 1){ + reverse_points(points[i],x,y,z); + } + } + for(j=0;j 0 ){ + return 0; //counter-clockwise + }else{ + return 1; //clockwise + } +} + -- 2.40.0