22 #include "../postgis_config.h" 35 #include <sys/param.h> 38 #include "../liblwgeom/liblwgeom.h" 39 #include "../liblwgeom/lwgeom_log.h" 42 #define MAX_DBF_FIELD_SIZE 254 46 static int reverse_points(
int num_points,
double *
x,
double *
y,
double *z,
double *m);
47 static int is_clockwise(
int num_points,
double *
x,
double *
y,
double *z);
74 const uint8_t ndr_nan[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x7f};
77 memcpy(&double_nan, ndr_nan, 8);
88 double *xpts, *ypts, *zpts, *mpts;
91 xpts =
malloc(
sizeof(
double));
92 ypts =
malloc(
sizeof(
double));
93 zpts =
malloc(
sizeof(
double));
94 mpts =
malloc(
sizeof(
double));
105 LWDEBUGF(4,
"Point: %g %g %g %g", xpts[0], ypts[0], zpts[0], mpts[0]);
124 double *xpts, *ypts, *zpts, *mpts;
134 for (i = 0; i < lwmultipoint->
ngeoms; i++)
143 LWDEBUGF(4,
"MultiPoint %d - Point: %g %g %g %g", i, xpts[i], ypts[i], zpts[i], mpts[i]);
163 double *xpts, *ypts, *zpts, *mpts;
165 int *shpparts, shppointtotal = 0, shppoint = 0;
171 for (i = 0; i < lwpolygon->
nrings; i++)
175 xpts =
malloc(
sizeof(
double) * shppointtotal);
176 ypts =
malloc(
sizeof(
double) * shppointtotal);
177 zpts =
malloc(
sizeof(
double) * shppointtotal);
178 mpts =
malloc(
sizeof(
double) * shppointtotal);
180 LWDEBUGF(4,
"Total number of points: %d", shppointtotal);
183 for (i = 0; i < lwpolygon->
nrings; i++)
186 shpparts[i] = shppoint;
192 xpts[shppoint] = p4d.
x;
193 ypts[shppoint] = p4d.
y;
194 zpts[shppoint] = p4d.
z;
195 mpts[shppoint] = p4d.
m;
197 LWDEBUGF(4,
"Polygon Ring %d - Point: %g %g %g %g", i, xpts[shppoint], ypts[shppoint], zpts[shppoint], mpts[shppoint]);
210 &xpts[shpparts[i]], &ypts[shpparts[i]], NULL) )
212 LWDEBUG(4,
"Outer ring not clockwise, forcing clockwise\n");
215 &xpts[shpparts[i]], &ypts[shpparts[i]],
216 &zpts[shpparts[i]], &mpts[shpparts[i]]);
222 &xpts[shpparts[i]], &ypts[shpparts[i]], NULL) )
224 LWDEBUGF(4,
"Inner ring %d not counter-clockwise, forcing counter-clockwise\n", i);
227 &xpts[shpparts[i]], &ypts[shpparts[i]],
228 &zpts[shpparts[i]], &mpts[shpparts[i]]);
251 double *xpts, *ypts, *zpts, *mpts;
253 int *shpparts, shppointtotal = 0, shppoint = 0, shpringtotal = 0, shpring = 0;
258 for (i = 0; i < lwmultipolygon->
ngeoms; i++)
260 for (j = 0; j < lwmultipolygon->
geoms[i]->
nrings; j++)
268 shpparts =
malloc(
sizeof(
int) * shpringtotal);
271 xpts =
malloc(
sizeof(
double) * shppointtotal);
272 ypts =
malloc(
sizeof(
double) * shppointtotal);
273 zpts =
malloc(
sizeof(
double) * shppointtotal);
274 mpts =
malloc(
sizeof(
double) * shppointtotal);
276 LWDEBUGF(4,
"Total number of rings: %d Total number of points: %d", shpringtotal, shppointtotal);
279 for (i = 0; i < lwmultipolygon->
ngeoms; i++)
281 for (j = 0; j < lwmultipolygon->
geoms[i]->
nrings; j++)
284 shpparts[shpring] = shppoint;
286 LWDEBUGF(4,
"Ring offset: %d", shpring);
292 xpts[shppoint] = p4d.
x;
293 ypts[shppoint] = p4d.
y;
294 zpts[shppoint] = p4d.
z;
295 mpts[shppoint] = p4d.
m;
297 LWDEBUGF(4,
"MultiPolygon %d Polygon Ring %d - Point: %g %g %g %g", i, j, xpts[shppoint], ypts[shppoint], zpts[shppoint], mpts[shppoint]);
310 &xpts[shpparts[shpring]], &ypts[shpparts[shpring]], NULL) )
312 LWDEBUG(4,
"Outer ring not clockwise, forcing clockwise\n");
315 &xpts[shpparts[shpring]], &ypts[shpparts[shpring]],
316 &zpts[shpparts[shpring]], &mpts[shpparts[shpring]]);
322 &xpts[shpparts[shpring]], &ypts[shpparts[shpring]], NULL) )
324 LWDEBUGF(4,
"Inner ring %d not counter-clockwise, forcing counter-clockwise\n", i);
327 &xpts[shpparts[shpring]], &ypts[shpparts[shpring]],
328 &zpts[shpparts[shpring]], &mpts[shpparts[shpring]]);
355 double *xpts, *ypts, *zpts, *mpts;
374 LWDEBUGF(4,
"Linestring - Point: %g %g %g %g", i, xpts[i], ypts[i], zpts[i], mpts[i]);
394 double *xpts, *ypts, *zpts, *mpts;
396 int *shpparts, shppointtotal = 0, shppoint = 0;
399 shpparts =
malloc(
sizeof(
int) * lwmultilinestring->
ngeoms);
402 for (i = 0; i < lwmultilinestring->
ngeoms; i++)
405 LWDEBUGF(3,
"Total number of points: %d", shppointtotal);
408 xpts =
malloc(
sizeof(
double) * shppointtotal);
409 ypts =
malloc(
sizeof(
double) * shppointtotal);
410 zpts =
malloc(
sizeof(
double) * shppointtotal);
411 mpts =
malloc(
sizeof(
double) * shppointtotal);
414 for (i = 0; i < lwmultilinestring->
ngeoms; i++)
417 shpparts[i] = shppoint;
423 xpts[shppoint] = p4d.
x;
424 ypts[shppoint] = p4d.
y;
425 zpts[shppoint] = p4d.
z;
426 mpts[shppoint] = p4d.
m;
428 LWDEBUGF(4,
"Linestring %d - Point: %g %g %g %g", i, xpts[shppoint], ypts[shppoint], zpts[shppoint], mpts[shppoint]);
455 for (i=0; i <num_points; i++)
493 double x_change,y_change,
area;
494 double *x_new, *y_new;
497 x_new = (
double *)
malloc(
sizeof(
double) * num_points);
498 y_new = (
double *)
malloc(
sizeof(
double) * num_points);
503 for (i=0; i < num_points ; i++)
505 x_new[i] = x[i] - x_change;
506 y_new[i] = y[i] - y_change;
509 for (i=0; i < num_points - 1; i++)
512 area += (x[i] * y[i+1]) - (y[i] * x[i+1]);
545 query = (
char *)
malloc(strlen(fname)+strlen(table)+
548 "select max(octet_length(\"%s\"::text)) from \"%s\".\"%s\"",
549 fname, schema, table);
553 query = (
char *)
malloc(strlen(fname)+strlen(table)+46);
555 "select max(octet_length(\"%s\"::text)) from \"%s\"",
559 LWDEBUGF(4,
"maxFieldLenQuery: %s\n", query);
561 res = PQexec(conn, query);
563 if ( ! res || PQresultStatus(res) != PGRES_TUPLES_OK )
565 printf(
_(
"Querying for maximum field length: %s"),
566 PQerrorMessage(conn));
570 if (PQntuples(res) <= 0 )
575 size = atoi(PQgetvalue(res, 0, 0));
585 if ( (((
char *)(&test))[0]) == 1)
617 return "MultiPointZ";
625 return "MultiPointM";
643 return "****************";
678 buf[0] = toupper(in[0]);
703 hexewkb =
malloc(size * 2 + 1);
704 for (i=0; i<size; ++i)
deparse_hex(ewkb[i], &hexewkb[i * 2]);
705 hexewkb[size * 2] =
'\0';
720 char *pszFullname, *pszBasename;
723 char *pszFilename = state->
shp_file;
724 char *schema = state->
schema;
725 char *table = state->
table;
732 char *esc_geo_col_name;
744 size += 3 * strlen(schema);
747 esc_table = (
char *)
malloc(3 * strlen(table) + 1);
748 esc_geo_col_name = (
char *)
malloc(3 * strlen(geo_col_name) + 1);
749 PQescapeStringConn(state->
conn, esc_table, table, strlen(table), &error);
750 PQescapeStringConn(state->
conn, esc_geo_col_name, geo_col_name, strlen(geo_col_name), &error);
753 query = (
char *)
malloc(size);
754 if ( ! query )
return 0;
765 esc_schema = (
char *)
malloc(2 * strlen(schema) + 1);
766 PQescapeStringConn(state->
conn, esc_schema, schema, strlen(schema), &error);
767 sprintf(query,
"SELECT COALESCE((SELECT sr.srtext " 768 " FROM geometry_columns As gc INNER JOIN spatial_ref_sys sr ON sr.srid = gc.srid " 769 " WHERE gc.f_table_schema = '%s' AND gc.f_table_name = '%s' AND gc.f_geometry_column = '%s' LIMIT 1), " 770 " (SELECT CASE WHEN COUNT(DISTINCT sr.srid) > 1 THEN 'm' ELSE MAX(sr.srtext) END As srtext " 771 " FROM \"%s\".\"%s\" As g INNER JOIN spatial_ref_sys sr ON sr.srid = ST_SRID((g.\"%s\")::geometry)) , ' ') As srtext ",
772 esc_schema, esc_table,esc_geo_col_name, schema, table, geo_col_name);
777 sprintf(query,
"SELECT COALESCE((SELECT sr.srtext " 778 " FROM geometry_columns As gc INNER JOIN spatial_ref_sys sr ON sr.srid = gc.srid " 779 " WHERE gc.f_table_name = '%s' AND gc.f_geometry_column = '%s' AND pg_table_is_visible((gc.f_table_schema || '.' || gc.f_table_name)::regclass) LIMIT 1), " 780 " (SELECT CASE WHEN COUNT(DISTINCT sr.srid) > 1 THEN 'm' ELSE MAX(sr.srtext) END as srtext " 781 " FROM \"%s\" As g INNER JOIN spatial_ref_sys sr ON sr.srid = ST_SRID((g.\"%s\")::geometry)), ' ') As srtext ",
782 esc_table, esc_geo_col_name, table, geo_col_name);
787 free(esc_geo_col_name);
789 res = PQexec(state->
conn, query);
791 if ( ! res || PQresultStatus(res) != PGRES_TUPLES_OK )
793 snprintf(state->
message,
SHPDUMPERMSGLEN,
_(
"WARNING: Could not execute prj query: %s"), PQresultErrorMessage(res));
799 for (i=0; i < PQntuples(res); i++)
801 srtext = PQgetvalue(res, i, 0);
802 if (strcmp(srtext,
"m") == 0)
804 snprintf(state->
message,
SHPDUMPERMSGLEN,
_(
"WARNING: Mixed set of spatial references. No prj file will be generated"));
811 if (srtext[0] ==
' ')
813 snprintf(state->
message,
SHPDUMPERMSGLEN,
_(
"WARNING: Cannot determine spatial reference (empty table or unknown spatial ref). No prj file will be generated."));
824 pszBasename = (
char *)
malloc(strlen(pszFilename)+5);
825 strcpy( pszBasename, pszFilename );
826 for ( i = strlen(pszBasename)-1;
827 i > 0 && pszBasename[i] !=
'.' && pszBasename[i] !=
'/' 828 && pszBasename[i] !=
'\\';
831 if ( pszBasename[i] ==
'.' )
832 pszBasename[i] =
'\0';
834 pszFullname = (
char *)
malloc(strlen(pszBasename) + 5);
835 sprintf( pszFullname,
"%s.prj", pszBasename );
842 fp = fopen( pszFullname,
"wb" );
851 result = fputs (srtext,fp);
852 LWDEBUGF(3,
"\n result %d proj SRText is %s .\n", result, srtext);
901 sprintf(query,
"SELECT count(1), max(ST_zmflag(\"%s\"::geometry)), geometrytype(\"%s\"::geometry) FROM \"%s\".\"%s\" GROUP BY 3",
908 sprintf(query,
"SELECT count(1), max(ST_zmflag(\"%s\"::geometry)), geometrytype(\"%s\"::geometry) FROM \"%s\" GROUP BY 3",
919 sprintf(query,
"SELECT count(1) FROM \"%s\".\"%s\"", state->
schema, state->
table);
925 sprintf(query,
"SELECT count(1) FROM \"%s\"", state->
table);
929 LWDEBUGF(3,
"Table metadata query: %s\n", query);
931 res = PQexec(state->
conn, query);
934 if (PQresultStatus(res) != PGRES_TUPLES_OK)
936 snprintf(state->
message,
SHPDUMPERMSGLEN,
_(
"ERROR: Could not execute table metadata query: %s"), PQresultErrorMessage(res));
942 if (PQntuples(res) == 0)
963 int typefound = 0, typemismatch = 0;
967 for (i = 0; i < PQntuples(res); i++)
970 if (PQgetisnull(res, i, 2))
972 state->
rowcount += atoi(PQgetvalue(res, i, 0));
1028 state->
rowcount += atoi(PQgetvalue(res, i, 0));
1033 tmpint = atoi(PQgetvalue(res, i, 1));
1130 state->
rowcount = atoi(PQgetvalue(res, 0, 0));
1151 config->
table = NULL;
1182 state->
table = NULL;
1204 (conn->
host ? strlen(conn->
host) : 0) + (conn->
port ? strlen(conn->
port) : 0) +
1208 connstring =
malloc(connlen);
1209 memset(connstring, 0, connlen);
1213 strcat(connstring,
" host=");
1214 strcat(connstring, conn->
host);
1219 strcat(connstring,
" port=");
1220 strcat(connstring, conn->
port);
1225 strcat(connstring,
" user=");
1226 strcat(connstring, conn->
username);
1231 strcat(connstring,
" password='");
1232 strcat(connstring, conn->
password);
1233 strcat(connstring,
"'");
1238 strcat(connstring,
" dbname=");
1239 strcat(connstring, conn->
database);
1242 if ( ! getenv(
"PGCLIENTENCODING") )
1244 strcat(connstring,
" client_encoding=UTF8");
1257 char *connstring, *tmpvalue;
1263 state->
conn = PQconnectdb(connstring);
1264 if (PQstatus(state->
conn) == CONNECTION_BAD)
1272 res = PQexec(state->
conn,
"SET DATESTYLE='ISO'");
1273 if (PQresultStatus(res) != PGRES_COMMAND_OK)
1284 res = PQexec(state->
conn,
"SELECT postgis_version()");
1285 if (PQresultStatus(res) != PGRES_TUPLES_OK)
1293 tmpvalue = PQgetvalue(res, 0, 0);
1299 res = PQexec(state->
conn,
"SELECT oid FROM pg_type WHERE typname = 'geometry'");
1300 if (PQresultStatus(res) != PGRES_TUPLES_OK)
1308 if (PQntuples(res) > 0)
1310 tmpvalue = PQgetvalue(res, 0, 0);
1324 res = PQexec(state->
conn,
"SELECT oid FROM pg_type WHERE typname = 'geography'");
1325 if (PQresultStatus(res) != PGRES_TUPLES_OK)
1327 snprintf(state->
message,
SHPDUMPERMSGLEN,
_(
"Error looking up geography oid: %s"), PQresultErrorMessage(res));
1333 if (PQntuples(res) > 0)
1336 tmpvalue = PQgetvalue(res, 0, 0);
1356 int gidfound = 0, i, j, ret, status;
1371 sprintf(state->
table,
"__pgsql2shp%lu_tmp_table", (
long)getpid());
1376 res = PQexec(state->
conn, query);
1380 if (PQresultStatus(res) != PGRES_COMMAND_OK)
1401 sprintf(query,
"SELECT a.attname, a.atttypid, " 1402 "a.atttypmod, a.attlen FROM " 1403 "pg_attribute a, pg_class c, pg_namespace n WHERE " 1404 "n.nspname = '%s' AND a.attrelid = c.oid AND " 1405 "n.oid = c.relnamespace AND " 1406 "a.atttypid != 0 AND " 1407 "a.attnum > 0 AND c.relname = '%s'", state->
schema, state->
table);
1413 sprintf(query,
"SELECT a.attname, a.atttypid, " 1414 "a.atttypmod, a.attlen FROM " 1415 "pg_attribute a, pg_class c WHERE " 1416 "a.attrelid = c.oid and a.attnum > 0 AND " 1417 "a.atttypid != 0 AND " 1418 "c.relname = '%s' AND " 1419 "pg_catalog.pg_table_is_visible(c.oid)", state->
table);
1422 LWDEBUGF(3,
"query is: %s\n", query);
1424 res = PQexec(state->
conn, query);
1427 if (PQresultStatus(res) != PGRES_TUPLES_OK)
1434 if (!PQntuples(res))
1450 if ( getenv(
"PGCLIENTENCODING") )
1478 for (i = 0; i < PQntuples(res); i++)
1482 int pgfieldtype, pgtypmod, pgfieldlen;
1485 int dbffieldtype, dbffieldsize, dbffielddecs;
1488 pgfieldname = PQgetvalue(res, i, 0);
1489 pgfieldtype = atoi(PQgetvalue(res, i, 1));
1490 pgtypmod = atoi(PQgetvalue(res, i, 2));
1491 pgfieldlen = atoi(PQgetvalue(res, i, 3));
1522 if (!strcmp(pgfieldname,
"gid") )
1544 dbffieldname =
malloc(11);
1545 strncpy(dbffieldname, ptr, 10);
1546 dbffieldname[10] =
'\0';
1555 strncpy(dbffieldname, mapped, 10);
1556 dbffieldname[10] =
'\0';
1566 if (!strncasecmp(dbffieldname, state->
dbffieldnames[j], 10))
1568 sprintf(dbffieldname,
"%.7s_%.2d", ptr, tmpint++);
1575 for (j = 0; j < strlen(dbffieldname); j++)
1576 dbffieldname[j] = toupper(dbffieldname[j]);
1579 if (strcasecmp(dbffieldname, pgfieldname))
1581 if ( snprintf(buf, 256,
_(
"Warning, field %s renamed to %s\n"),
1582 pgfieldname, dbffieldname) >= 256 )
1598 if (pgfieldtype == 21)
1605 dbffieldtype = FTInteger;
1611 else if (pgfieldtype == 23)
1618 dbffieldtype = FTInteger;
1624 else if (pgfieldtype == 20)
1631 dbffieldtype = FTInteger;
1645 else if (pgfieldtype == 700 || pgfieldtype == 701 || pgfieldtype == 1700)
1647 dbffieldtype = FTDouble;
1655 else if (pgfieldtype == 16)
1657 dbffieldtype = FTLogical;
1665 else if (pgfieldtype == 1082)
1667 dbffieldtype = FTDate;
1675 else if (pgfieldtype == 1083 || pgfieldtype == 1266 || pgfieldtype == 1114 || pgfieldtype == 1184)
1688 secondsize = pgtypmod + 1;
1700 if (pgfieldtype == 1083)
1702 dbffieldsize = 8 + secondsize;
1705 else if (pgfieldtype == 1266)
1707 dbffieldsize = 8 + secondsize + 9;
1710 else if (pgfieldtype == 1114)
1712 dbffieldsize = 13 + 1 + 8 + secondsize;
1715 else if (pgfieldtype == 1184)
1717 dbffieldsize = 13 + 1 + 8 + secondsize + 9;
1720 dbffieldtype = FTString;
1727 else if (pgfieldtype == 2950)
1729 dbffieldtype = FTString;
1739 else if ((pgfieldtype == 1042 || pgfieldtype == 1043) && pgtypmod != -1)
1745 dbffieldtype = FTString;
1746 dbffieldsize = pgtypmod - 4;
1751 else if (dbffieldtype == -1)
1759 if (dbffieldsize == -1)
1770 dbffieldtype = FTString;
1777 snprintf(buf, 256,
_(
"Warning: values of field '%s' exceeding maximum dbf field width (%d) " 1786 LWDEBUGF(3,
"DBF FIELD_NAME: %s, SIZE: %d\n", dbffieldname, dbffieldsize);
1788 if (dbffieldtype != 9)
1791 if (
DBFAddField(state->
dbf, dbffieldname, dbffieldtype, dbffieldsize, dbffielddecs) == -1)
1793 snprintf(state->
message,
SHPDUMPERMSGLEN,
_(
"Error: field %s of type %d could not be created."), dbffieldname, dbffieldtype);
1832 snprintf(buf, 256,
_(
"No geometry column found.\nThe DBF file will be created but not the shx or shp files.\n"));
1897 sprintf(buf,
"asbinary(%s::geometry, 'XDR') AS _geoX",
1909 sprintf(buf,
"asbinary(%s::geometry, 'NDR') AS _geoX",
1919 sprintf(buf,
" FROM \"%s\".\"%s\"", state->
schema, state->
table);
1923 sprintf(buf,
" FROM \"%s\"", state->
table);
1931 sprintf(buf,
" ORDER BY \"gid\"");
1944 res = PQexec(state->
conn,
"BEGIN");
1945 if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
1956 if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
1958 snprintf(state->
message,
SHPDUMPERMSGLEN,
_(
"Error executing main scan query: %s"), PQresultErrorMessage(res));
1982 char *hexewkb = NULL;
1983 unsigned char *hexewkb_binary = NULL;
1989 int i, geocolnum = 0;
2007 if (PQresultStatus(state->
fetchres) != PGRES_TUPLES_OK)
2020 geocolnum = PQfnumber(state->
fetchres,
"_geoX");
2077 LWDEBUG(4,
"PostGIS >= 1.0, non-binary cursor");
2081 hexewkb_binary = PQunescapeBytea((
unsigned char *)val, &hexewkb_len);
2086 LWDEBUG(4,
"PostGIS < 1.0, non-binary cursor");
2091 hexewkb =
malloc(hexewkb_len + 1);
2092 strncpy(hexewkb, val, hexewkb_len + 1);
2097 LWDEBUG(4,
"PostGIS (any version) using binary cursor");
2104 LWDEBUGF(4,
"HexEWKB - length: %d value: %s", strlen(hexewkb), hexewkb);
2119 switch (lwgeom->
type)
2174 if (hexewkb)
free(hexewkb);
2175 if (hexewkb_binary) PQfreemem(hexewkb_binary);
2228 PQfinish(state->
conn);
2274 char *result =
malloc(strlen(s) * 2 + 3);
static SHPObject * create_point(SHPDUMPERSTATE *state, LWPOINT *lwpoint)
SHPObject SHPAPI_CALL1 * SHPCreateSimpleObject(int nSHPType, int nVertices, const double *padfX, const double *padfY, const double *padfZ){ return(SHPCreateObject(nSHPType, -1, 0, NULL, NULL, nVertices, padfX, padfY, padfZ, NULL)
char * column_map_filename
void colmap_clean(colmap *map)
static SHPObject * create_polygon(SHPDUMPERSTATE *state, LWPOLY *lwpolygon)
char * convert_bytes_to_hex(uint8_t *ewkb, size_t size)
Binary to hexewkb conversion function.
static SHPObject * create_multilinestring(SHPDUMPERSTATE *state, LWMLINE *lwmultilinestring)
SHPObject SHPAPI_CALL1 * SHPCreateObject(int nSHPType, int nShapeId, int nParts, const int *panPartStart, const int *panPartType, int nVertices, const double *padfX, const double *padfY, const double *padfZ, const double *padfM);SHPObject SHPAPI_CALL1(*) SHPCreateSimpleObject(int nSHPType, int nVertices, const double *padfX, const double *padfY, const double *padfZ
int colmap_read(const char *filename, colmap *map, char *errbuf, size_t errbuflen)
Read the content of filename into a symbol map.
static int is_bigendian(void)
void deparse_hex(uint8_t str, char *result)
Convert a char into a human readable hex digit.
int ShpDumperOpenTable(SHPDUMPERSTATE *state)
Datum area(PG_FUNCTION_ARGS)
void lwgeom_free(LWGEOM *geom)
static char * goodDBFValue(char *in, char fieldType)
Make appropriate formatting of a DBF value based on type.
int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m)
Calculate type integer and dimensional flags from string input.
int SHPAPI_CALL DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField, void *pValue)
#define LWDEBUG(level, msg)
DBFHandle SHPAPI_CALL DBFCreateEx(const char *pszFilename, const char *pszCodePage)
void SHPAPI_CALL SHPDestroyObject(SHPObject *psObject)
int ShpLoaderGenerateShapeRow(SHPDUMPERSTATE *state)
SHPHandle SHPAPI_CALL SHPCreate(const char *pszShapeFile, int nShapeType)
SHPDUMPERSTATE * ShpDumperCreate(SHPDUMPERCONFIG *config)
int ShpDumperCloseTable(SHPDUMPERSTATE *state)
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
static int getTableInfo(SHPDUMPERSTATE *state)
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
static int reverse_points(int num_points, double *x, double *y, double *z, double *m)
void set_dumper_config_defaults(SHPDUMPERCONFIG *config)
static SHPCONNECTIONCONFIG * conn
LWMPOLY * lwgeom_as_lwmpoly(const LWGEOM *lwgeom)
void colmap_init(colmap *map)
#define LW_PARSER_CHECK_NONE
static SHPObject * create_linestring(SHPDUMPERSTATE *state, LWLINE *lwlinestring)
#define MAX_DBF_FIELD_SIZE
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
POINT4D getPoint4d(const POINTARRAY *pa, int n)
static int getMaxFieldSize(PGconn *conn, char *schema, char *table, char *fname)
static int is_clockwise(int num_points, double *x, double *y, double *z)
SHPCONNECTIONCONFIG * conn
LWMLINE * lwgeom_as_lwmline(const LWGEOM *lwgeom)
int lwtype_is_collection(uint8_t type)
Determine whether a type number is a collection or not.
int SHPAPI_CALL DBFAddField(DBFHandle psDBF, const char *pszFieldName, DBFFieldType eType, int nWidth, int nDecimals)
static SHPObject * create_multipoint(SHPDUMPERSTATE *state, LWMPOINT *lwmultipoint)
char * ShpDumperGetConnectionStringFromConn(SHPCONNECTIONCONFIG *conn)
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
void ShpDumperDestroy(SHPDUMPERSTATE *state)
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
static int projFileCreate(SHPDUMPERSTATE *state)
Creates ESRI .prj file for this shp output It looks in the spatial_ref_sys table and outputs the srte...
int ShpDumperGetRecordCount(SHPDUMPERSTATE *state)
char * encoding2codepage(const char *encoding)
char * quote_identifier(const char *s)
int SHPAPI_CALL SHPWriteObject(SHPHandle psSHP, int nShapeId, SHPObject *psObject)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
LWMPOINT * lwgeom_as_lwmpoint(const LWGEOM *lwgeom)
static char * nullDBFValue(char fieldType)
void SHPAPI_CALL DBFClose(DBFHandle psDBF)
static SHPObject * create_multipolygon(SHPDUMPERSTATE *state, LWMPOLY *lwmultipolygon)
int ShpDumperConnectDatabase(SHPDUMPERSTATE *state)
void SHPAPI_CALL SHPClose(SHPHandle hSHP)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
char message[SHPDUMPERMSGLEN]
static SHPObject * create_point_empty(SHPDUMPERSTATE *state, LWPOINT *lwpoint)
char * shapetypename(int num)
#define LWDEBUGF(level, msg,...)
const char * colmap_dbf_by_pg(colmap *map, const char *pgname)