SHPObject * (*shape_creator)(byte *, int);
int big_endian = 0;
int pgis_major_version;
+int zmflag;
/* Prototypes */
int getMaxFieldSize(PGconn *conn, char *schema, char *table, char *fname);
void skipdouble(byte **c);
void dump_wkb(byte *wkb);
byte * HexDecode(byte *hex);
-#define WKB3DOFFSET 0x80000000
-#define WKB4DOFFSET 0x40000000
+#define WKBZOFFSET 0x80000000
+#define WKBMOFFSET 0x40000000
static void exit_nicely(PGconn *conn){
}
int
-main(int ARGC, char **ARGV){
+main(int ARGC, char **ARGV)
+{
char *query=NULL;
int row;
PGresult *res;
includegid=0;
unescapedattrs=0;
binary = 0;
+ zmflag = 0;
#ifdef DEBUG
FILE *debug;
#endif
}
- printf("Output shape type is: %s\n", shapetypename(outshptype));
+ printf("Output shape: %s\n", shapetypename(outshptype));
/*
{
byte *ptr = str;
uint32 type;
- int ndims = 2;
+ int ndims;
int wkb_big_endian;
// skip byte order
// get type
type = getint(ptr);
- if ( type&WKB3DOFFSET ) ndims = 3;
- if ( type&WKB4DOFFSET ) ndims = 4;
+ ndims=2;
+ if ( type&WKBZOFFSET ) ndims++;
+ if ( type&WKBMOFFSET )
+ {
- type &= ~WKB3DOFFSET;
- type &= ~WKB4DOFFSET;
+ ndims++;
+ }
+
+ type &= ~WKBZOFFSET;
+ type &= ~WKBMOFFSET;
switch(type)
{
create_multiline3D_WKB (byte *wkb)
{
SHPObject *obj;
- double *x=NULL, *y=NULL, *z=NULL;
+ double *x=NULL, *y=NULL, *zm=NULL;
int nparts=0, *part_index=NULL, totpoints=0, nlines=0;
int li;
x = realloc(x, sizeof(double)*(totpoints+npoints));
y = realloc(y, sizeof(double)*(totpoints+npoints));
- z = realloc(z, sizeof(double)*(totpoints+npoints));
+ zm = realloc(zm, sizeof(double)*(totpoints+npoints));
/* wkb now points at first point */
for (pn=0; pn<npoints; pn++)
{
x[totpoints+pn] = popdouble(&wkb);
y[totpoints+pn] = popdouble(&wkb);
- z[totpoints+pn] = popdouble(&wkb);
+ zm[totpoints+pn] = popdouble(&wkb);
}
part_index[li] = totpoints;
totpoints += npoints;
}
- obj = SHPCreateObject(outshptype, -1, nparts,
- part_index, NULL, totpoints,
- x, y, z, NULL);
+ if ( zmflag == 1 ) {
+ obj = SHPCreateObject(outshptype, -1, nparts,
+ part_index, NULL, totpoints,
+ x, y, NULL, zm);
+ } else {
+ obj = SHPCreateObject(outshptype, -1, nparts,
+ part_index, NULL, totpoints,
+ x, y, zm, NULL);
+ }
- free(part_index); free(x); free(y); free(z);
+ free(part_index); free(x); free(y); free(zm);
return obj;
}
SHPObject *
create_line3D_WKB (byte *wkb)
{
- double *x=NULL, *y=NULL, *z=NULL;
+ double *x=NULL, *y=NULL, *zm=NULL;
uint32 npoints=0, pn;
SHPObject *obj;
x = malloc(sizeof(double)*(npoints));
y = malloc(sizeof(double)*(npoints));
- z = malloc(sizeof(double)*(npoints));
+ zm = malloc(sizeof(double)*(npoints));
/* wkb now points at first point */
for (pn=0; pn<npoints; pn++)
{
x[pn] = popdouble(&wkb);
y[pn] = popdouble(&wkb);
- z[pn] = popdouble(&wkb);
+ zm[pn] = popdouble(&wkb);
}
- obj = SHPCreateSimpleObject(outshptype, npoints, x, y, z);
- free(x); free(y); free(z);
+ if ( zmflag == 1 ) {
+ obj = SHPCreateObject(outshptype, -1, 0, NULL, NULL,
+ npoints, x, y, NULL, zm);
+ } else {
+ obj = SHPCreateObject(outshptype, -1, 0, NULL, NULL,
+ npoints, x, y, zm, NULL);
+ }
+
+ free(x); free(y); free(zm);
return obj;
}
create_point3D_WKB(byte *wkb)
{
SHPObject *obj;
- double x, y, z;
+ double x, y, zm;
// skip byteOrder and wkbType
skipbyte(&wkb); skipint(&wkb);
x = popdouble(&wkb);
y = popdouble(&wkb);
- z = popdouble(&wkb);
+ zm = popdouble(&wkb);
- if ( geotype == POINTTYPE )
- {
- obj = SHPCreateSimpleObject(outshptype,1,&x,&y,&z);
- }
- else if ( geotype == MULTIPOINTTYPE )
- {
- //printf( "create_point3D_WKB: fluffing to MULTIPOINT\n");
- obj = SHPCreateSimpleObject(outshptype, 1, &x, &y, &z);
- }
- else
- {
- printf( "ERROR: create_point2D_WKB called with wrong geometry type (%d)\n", geotype);
- return NULL;
+ if ( zmflag == 1 ) {
+ obj = SHPCreateObject(outshptype, -1, 0, NULL, NULL,
+ 1, &x, &y, NULL, &zm);
+ } else {
+ obj = SHPCreateObject(outshptype, -1, 0, NULL, NULL,
+ 1, &x, &y, &zm, NULL);
}
return obj;
create_multipoint3D_WKB(byte *wkb)
{
SHPObject *obj;
- double *x=NULL, *y=NULL, *z=NULL;
- int npoints;
- int pn;
+ double *x=NULL, *y=NULL, *zm=NULL;
+ uint32 npoints;
+ uint32 pn;
// skip byteOrder and type
skipbyte(&wkb); skipint(&wkb);
x = (double *)malloc(sizeof(double)*npoints);
y = (double *)malloc(sizeof(double)*npoints);
- z = (double *)malloc(sizeof(double)*npoints);
+ zm = (double *)malloc(sizeof(double)*npoints);
for (pn=0; pn<npoints; pn++)
{
+ skipbyte(&wkb); // byteOrder
+ skipint(&wkb); // wkbType
x[pn]=popdouble(&wkb);
y[pn]=popdouble(&wkb);
- z[pn]=popdouble(&wkb);
+ zm[pn]=popdouble(&wkb);
}
- obj = SHPCreateSimpleObject(outshptype,npoints,x,y,z);
- free(x); free(y); free(z);
+ if ( zmflag == 1 ) {
+ obj = SHPCreateObject(outshptype, -1, 0, NULL, NULL,
+ npoints, x, y, NULL, zm);
+ } else {
+ obj = SHPCreateObject(outshptype, -1, 0, NULL, NULL,
+ npoints, x, y, zm, NULL);
+ }
+
+ free(x); free(y); free(zm);
return obj;
}
{
SHPObject *obj;
int ri, nrings, totpoints=0, *part_index=NULL;
- double *x=NULL, *y=NULL, *z=NULL;
+ double *x=NULL, *y=NULL, *zm=NULL, *z=NULL;
// skip byteOrder and type
skipbyte(&wkb); skipint(&wkb);
x = realloc(x, sizeof(double)*(totpoints+npoints));
y = realloc(y, sizeof(double)*(totpoints+npoints));
- z = realloc(z, sizeof(double)*(totpoints+npoints));
+ zm = realloc(zm, sizeof(double)*(totpoints+npoints));
for (pn=0; pn<npoints; pn++)
{
x[totpoints+pn] = popdouble(&wkb);
y[totpoints+pn] = popdouble(&wkb);
- z[totpoints+pn] = popdouble(&wkb);
+ zm[totpoints+pn] = popdouble(&wkb);
}
/*
* First ring should be clockwise,
* other rings should be counter-clockwise
*/
+
+ // Set z to NULL if TYPEM
+ if ( zmflag == 1 ) z = NULL;
+ else z = zm+totpoints;
+
if ( !ri ) {
if ( ! is_clockwise(npoints, x+totpoints,
- y+totpoints, z+totpoints) ) {
+ y+totpoints, z) ) {
#if VERBOSE > 2
printf("Forcing CW\n");
#endif
reverse_points(npoints, x+totpoints,
- y+totpoints, z+totpoints, NULL);
+ y+totpoints, zm+totpoints, NULL);
}
} else {
if ( is_clockwise(npoints, x+totpoints,
- y+totpoints, z+totpoints) ) {
+ y+totpoints, z) ) {
#if VERBOSE > 2
printf("Forcing CCW\n");
#endif
reverse_points(npoints, x+totpoints,
- y+totpoints, z+totpoints, NULL);
+ y+totpoints, zm+totpoints, NULL);
}
}
totpoints += npoints;
}
- obj = SHPCreateObject(outshptype, -1, nrings,
- part_index, NULL, totpoints,
- x, y, z, NULL);
+ if ( zmflag == 1 ) {
+ obj = SHPCreateObject(outshptype, -1, nrings,
+ part_index, NULL, totpoints,
+ x, y, NULL, zm);
+ } else {
+ obj = SHPCreateObject(outshptype, -1, nrings,
+ part_index, NULL, totpoints,
+ x, y, zm, NULL);
+ }
free(part_index);
- free(x); free(y); free(z);
+ free(x); free(y); free(zm);
return obj;
}
int totpoints=0;
int *part_index=NULL;
int pi;
- double *x=NULL, *y=NULL, *z=NULL;
+ double *x=NULL, *y=NULL, *z=NULL, *zm=NULL;
// skip byteOrder and type
//printf("byteOrder is %d\n", popbyte(&wkb));
x = realloc(x, sizeof(double)*(totpoints+npoints));
y = realloc(y, sizeof(double)*(totpoints+npoints));
- z = realloc(z, sizeof(double)*(totpoints+npoints));
+ zm = realloc(zm, sizeof(double)*(totpoints+npoints));
/* wkb now points at first point */
for (pn=0; pn<npoints; pn++)
{
x[totpoints+pn] = popdouble(&wkb);
y[totpoints+pn] = popdouble(&wkb);
- z[totpoints+pn] = popdouble(&wkb);
+ zm[totpoints+pn] = popdouble(&wkb);
#if VERBOSE > 3
printf("Point%d (%f,%f)\n", pn, x[totpoints+pn], y[totpoints+pn]);
#endif
* First ring should be clockwise,
* other rings should be counter-clockwise
*/
+
+ // Set z to NULL if TYPEM
+ if ( zmflag == 1 ) z = NULL;
+ else z = zm+totpoints;
+
if ( !ri ) {
if (!is_clockwise(npoints, x+totpoints,
- y+totpoints, z+totpoints))
+ y+totpoints, z))
{
#if VERBOSE > 2
printf("Forcing CW\n");
#endif
reverse_points(npoints, x+totpoints,
- y+totpoints, z+totpoints, NULL);
+ y+totpoints, zm+totpoints, NULL);
}
} else {
if (is_clockwise(npoints, x+totpoints,
- y+totpoints, z+totpoints))
+ y+totpoints, z))
{
#if VERBOSE > 2
printf("Forcing CCW\n");
#endif
reverse_points(npoints, x+totpoints,
- y+totpoints, z+totpoints, NULL);
+ y+totpoints, zm+totpoints, NULL);
}
}
printf("End of polygons\n");
#endif
- obj = SHPCreateObject(outshptype, -1, nparts,
- part_index, NULL, totpoints,
- x, y, z, NULL);
+ if ( zmflag == 1 ) {
+ obj = SHPCreateObject(outshptype, -1, nparts,
+ part_index, NULL, totpoints,
+ x, y, NULL, zm);
+ } else {
+ obj = SHPCreateObject(outshptype, -1, nparts,
+ part_index, NULL, totpoints,
+ x, y, zm, NULL);
+ }
#if VERBOSE > 2
printf("Object created\n");
#endif
free(part_index);
- free(x); free(y); free(z);
+ free(x); free(y); free(zm);
return obj;
}
{
char query[1024];
PGresult *res;
- int zmflag;
if ( schema )
{
else printf("ByteOrder: unknown (%d)\n", byteOrder);
type = popint(&wkb);
- if ( type&WKB3DOFFSET ) printf ("Is 3D\n");
- type &= ~WKB3DOFFSET; // strip 3d flag
+ if ( type&WKBZOFFSET ) printf ("Has Z!\n");
+ if ( type&WKBMOFFSET ) printf ("Has M!\n");
+ type &= ~WKBZOFFSET; // strip Z flag
+ type &= ~WKBMOFFSET; // strip M flag
printf ("Type: %x\n", type);
printf("-----\n");
}
/**********************************************************************
* $Log$
+ * Revision 1.61 2004/10/07 17:15:28 strk
+ * Fixed TYPEM handling.
+ *
* Revision 1.60 2004/10/07 06:54:24 strk
* cleanups
*