Skip to content

Commit

Permalink
pc_bounds_to_geometry_wkb
Browse files Browse the repository at this point in the history
  • Loading branch information
mbredif committed Aug 30, 2018
1 parent 29fdb7c commit 38011ac
Show file tree
Hide file tree
Showing 15 changed files with 4,098 additions and 4,103 deletions.
22 changes: 19 additions & 3 deletions lib/cunit/cu_pc_patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,12 @@ test_patch_wkb()
PCPOINTLIST *pl1;
PCPATCH_UNCOMPRESSED *pu1, *pu2;
PCPATCH *pa1, *pa2, *pa3, *pa4;
size_t z1, z2;
uint8_t *wkb1, *wkb2;
size_t z1, z2, z3;
uint8_t *wkb1, *wkb2, *wkb3;
char *hexwkb;

static char *hexresult_ndr = "01030000000100000005000000000000000000000000000000000000000000000000000000CDCCCCCCCC8C4B40EC51B81E852B4440CDCCCCCCCC8C4B40EC51B81E852B4440000000000000000000000000000000000000000000000000";
static char *hexresult_xdr = "00000000030000000100000005000000000000000000000000000000000000000000000000404B8CCCCCCCCCCD40442B851EB851EC404B8CCCCCCCCCCD40442B851EB851EC000000000000000000000000000000000000000000000000";

pl1 = pc_pointlist_make(npts);

Expand All @@ -533,6 +537,7 @@ test_patch_wkb()
// str = pc_hexbytes_from_bytes(wkb1, z1);
// printf("str\n%s\n",str);
pa2 = pc_patch_from_wkb(simpleschema, wkb1, z1);
pcfree(wkb1);

// printf("pa2\n%s\n",pc_patch_to_string(pa2));

Expand All @@ -556,6 +561,18 @@ test_patch_wkb()
CU_ASSERT_EQUAL(pu1->npoints, pu2->npoints);
CU_ASSERT(memcmp(pu1->data, pu2->data, pu1->datasize) == 0);

wkb3 = pc_bounds_to_geometry_wkb(&pa1->bounds, simpleschema->srid, &z3);
hexwkb = pc_hexbytes_from_bytes(wkb3, z3);
if ( machine_endian() == PC_NDR )
{
CU_ASSERT_STRING_EQUAL(hexwkb, hexresult_ndr);
}
else
{
CU_ASSERT_STRING_EQUAL(hexwkb, hexresult_xdr);
}
pcfree(hexwkb);
pcfree(wkb3);

pc_pointlist_free(pl1);
pc_patch_free(pa1);
Expand All @@ -564,7 +581,6 @@ test_patch_wkb()
pc_patch_free(pa4);
pc_patch_free((PCPATCH*)pu1);
pc_patch_free((PCPATCH*)pu2);
pcfree(wkb1);
}


Expand Down
3 changes: 3 additions & 0 deletions lib/pc_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ int pc_patch_compute_extent(PCPATCH *patch);
/** True/false if bounds intersect */
int pc_bounds_intersects(const PCBOUNDS *b1, const PCBOUNDS *b2);

/** Return the bounds as an OGC WKB geometry */
uint8_t *pc_bounds_to_geometry_wkb(const PCBOUNDS *bounds, uint32_t srid, size_t *wkbsize);

/** Returns OGC WKB of the bounding diagonal of XY bounds */
uint8_t* pc_bounding_diagonal_wkb_from_bounds(const PCBOUNDS *bounds, const PCSCHEMA *schema, size_t *wkbsize);

Expand Down
77 changes: 77 additions & 0 deletions lib/pc_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,83 @@ static uint32_t srid_mask = 0x20000000;
static uint32_t m_mask = 0x40000000;
static uint32_t z_mask = 0x80000000;

uint8_t *
pc_bounds_to_geometry_wkb(const PCBOUNDS *bounds, uint32_t srid, size_t *wkbsize)
{
/* Bounds! */
double xmin = bounds->xmin;
double ymin = bounds->ymin;
double xmax = bounds->xmax;
double ymax = bounds->ymax;

static uint32_t srid_mask = 0x20000000;
static uint32_t npoints_by_type[] = { 0, 1, 2, 5 };
/* WKB POINT, LINESTRING or POLYGON */
uint32_t wkbtype = 1 + (xmin != xmax) + (ymin != ymax);
uint32_t npoints = npoints_by_type[wkbtype];
uint8_t *wkb, *ptr;
/* endian + (type + nrings? + npoints?) + npoints dbl pt */
size_t size = 1 + wkbtype * 4 + npoints * 2 * 8;

if ( srid )
{
wkbtype |= srid_mask;
size += 4;
}

wkb = pcalloc(size);
ptr = wkb;

ptr = wkb_set_char(ptr, machine_endian()); /* Endian flag */

ptr = wkb_set_uint32(ptr, wkbtype); /* TYPE = POINT, LINESTRING or POLYGON */

if ( srid )
{
ptr = wkb_set_uint32(ptr, srid); /* SRID */
}

switch ( wkbtype )
{
case 3 /* POLYGON */ : ptr = wkb_set_uint32(ptr, 1); /* NRINGS */
case 2 /* LINESTRING */ : ptr = wkb_set_uint32(ptr, npoints); /* NPOINTS */
}

/* Point 0 */
ptr = wkb_set_double(ptr, xmin);
ptr = wkb_set_double(ptr, ymin);

if ( wkbtype == 2 ) // LINESTRING
{
/* Point 1 */
ptr = wkb_set_double(ptr, xmax);
ptr = wkb_set_double(ptr, ymax);
}
else if( wkbtype == 3 ) // POLYGON
{
/* Point 1 */
ptr = wkb_set_double(ptr, xmin);
ptr = wkb_set_double(ptr, ymax);

/* Point 2 */
ptr = wkb_set_double(ptr, xmax);
ptr = wkb_set_double(ptr, ymax);

/* Point 3 */
ptr = wkb_set_double(ptr, xmax);
ptr = wkb_set_double(ptr, ymin);

/* Point 4 */
ptr = wkb_set_double(ptr, xmin);
ptr = wkb_set_double(ptr, ymin);
}

if ( wkbsize )
*wkbsize = size;

return wkb;
}

uint8_t *
pc_bounding_diagonal_wkb_from_bounds(
const PCBOUNDS *bounds, const PCSCHEMA *schema, size_t *wkbsize)
Expand Down
14 changes: 7 additions & 7 deletions pgsql/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
regression.out
regression.diffs
results/
tmp_check/
log/
Makefile
sqldefines.h
regression.out
regression.diffs
results/
tmp_check/
log/
Makefile
sqldefines.h
82 changes: 41 additions & 41 deletions pgsql/META.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
{
"name": "pointcloud",
"abstract": "LIDAR data support type and functions",
"description": "Point and Patch types for LIDAR storage. Aggregate and access functions. JSON and binary serializations. Compression.",
"version": "1.0.0",
"release_status": "unstable",
"maintainer": "Paul Ramsey",
"license": "bsd",
"provides": {
"pointcloud": {
"abstract": "LIDAR point and patch types and functions",
"version": "1.0.0",
"file": "",
"docfile": ""
}
}
"prereqs": {
"runtime": {
"requires": {
}
}
},
"generated_by": "Paul Ramsey",
"resources": {
"bugtracker": {
"web": "https://github.com/pgpointcloud/pointcloud"
},
"repository": {
"url": "",
"web": "https://github.com/pgpointcloud/pointcloud",
"type": "git"
}
},
"meta-spec": {
"version": "1.0.0",
"url": "http://pgxn.org/meta/spec.txt"
},
"tags": [
"gis", "lidar"
]
}
{
"name": "pointcloud",
"abstract": "LIDAR data support type and functions",
"description": "Point and Patch types for LIDAR storage. Aggregate and access functions. JSON and binary serializations. Compression.",
"version": "1.0.0",
"release_status": "unstable",
"maintainer": "Paul Ramsey",
"license": "bsd",
"provides": {
"pointcloud": {
"abstract": "LIDAR point and patch types and functions",
"version": "1.0.0",
"file": "",
"docfile": ""
}
}
"prereqs": {
"runtime": {
"requires": {
}
}
},
"generated_by": "Paul Ramsey",
"resources": {
"bugtracker": {
"web": "https://github.com/pgpointcloud/pointcloud"
},
"repository": {
"url": "",
"web": "https://github.com/pgpointcloud/pointcloud",
"type": "git"
}
},
"meta-spec": {
"version": "1.0.0",
"url": "http://pgxn.org/meta/spec.txt"
},
"tags": [
"gis", "lidar"
]
}
116 changes: 58 additions & 58 deletions pgsql/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
# pointcloud

include ../config.mk

SQLPP = @SQLPP@

OBJS = \
pc_inout.o \
pc_access.o \
pc_editor.o \
pc_pgsql.o

SED = sed
EXTENSION = pointcloud
EXTVERSION=$(shell cat ../Version.config)
EXTVERSION_MAJOR=$(shell cut -d. -f1,2 ../Version.config)
MODULE_big = $(EXTENSION)-$(EXTVERSION_MAJOR)
UPGRADABLE = 1.1.0 1.1.1

UPGRADES = \
$(shell echo $(UPGRADABLE) | \
$(SED) 's/^/$(EXTENSION)--/' | \
$(SED) 's/$$/--$(EXTVERSION).sql/' | \
$(SED) 's/ /--$(EXTVERSION).sql $(EXTENSION)--/g') \
$(EXTENSION)--$(EXTVERSION)--$(EXTVERSION)next.sql \
$(EXTENSION)--$(EXTVERSION)next--$(EXTVERSION).sql

DATA_built = \
$(EXTENSION).control \
$(EXTENSION)--$(EXTVERSION).sql \
$(UPGRADES)

REGRESS = pointcloud pointcloud_columns schema

ifneq ("$(LAZPERF_STATUS)", "disabled")
REGRESS += pointcloud-laz
endif

# Add in build/link flags for lib
PG_CPPFLAGS += -I../lib
SHLIB_LINK += ../lib/$(LIB_A) ../lib/$(LIB_A_LAZPERF) -lstdc++ $(filter -lm, $(LIBS)) $(XML2_LDFLAGS) $(ZLIB_LDFLAGS)

# We are going to use PGXS for sure
include $(PGXS)

$(EXTENSION).control: $(EXTENSION).control.in Makefile
$(SED) -e 's/#POINTCLOUD_VERSION#/$(EXTVERSION)/' \
-e 's/#POINTCLOUD_VERSION_MAJOR#/$(EXTVERSION_MAJOR)/' $< > $@

$(EXTENSION)--$(EXTVERSION).sql: $(EXTENSION).sql.in Makefile
$(SQLPP) -I. $< | $(SED) -e 's/#POINTCLOUD_VERSION#/$(EXTVERSION)/' > $@

# NOTE: relies on PERL being defined by PGXS
$(EXTENSION)--%--$(EXTVERSION).sql: $(EXTENSION)--$(EXTVERSION).sql ../util/proc_upgrade.pl
cat $< | ../util/proc_upgrade.pl > $@

$(EXTENSION)--%--$(EXTVERSION)next.sql: $(EXTENSION)--$(EXTVERSION)next--$(EXTVERSION).sql
ln -f $< $@
# pointcloud

include ../config.mk

SQLPP = @SQLPP@

OBJS = \
pc_inout.o \
pc_access.o \
pc_editor.o \
pc_pgsql.o

SED = sed
EXTENSION = pointcloud
EXTVERSION=$(shell cat ../Version.config)
EXTVERSION_MAJOR=$(shell cut -d. -f1,2 ../Version.config)
MODULE_big = $(EXTENSION)-$(EXTVERSION_MAJOR)
UPGRADABLE = 1.1.0 1.1.1

UPGRADES = \
$(shell echo $(UPGRADABLE) | \
$(SED) 's/^/$(EXTENSION)--/' | \
$(SED) 's/$$/--$(EXTVERSION).sql/' | \
$(SED) 's/ /--$(EXTVERSION).sql $(EXTENSION)--/g') \
$(EXTENSION)--$(EXTVERSION)--$(EXTVERSION)next.sql \
$(EXTENSION)--$(EXTVERSION)next--$(EXTVERSION).sql

DATA_built = \
$(EXTENSION).control \
$(EXTENSION)--$(EXTVERSION).sql \
$(UPGRADES)

REGRESS = pointcloud pointcloud_columns schema

ifneq ("$(LAZPERF_STATUS)", "disabled")
REGRESS += pointcloud-laz
endif

# Add in build/link flags for lib
PG_CPPFLAGS += -I../lib
SHLIB_LINK += ../lib/$(LIB_A) ../lib/$(LIB_A_LAZPERF) -lstdc++ $(filter -lm, $(LIBS)) $(XML2_LDFLAGS) $(ZLIB_LDFLAGS)

# We are going to use PGXS for sure
include $(PGXS)

$(EXTENSION).control: $(EXTENSION).control.in Makefile
$(SED) -e 's/#POINTCLOUD_VERSION#/$(EXTVERSION)/' \
-e 's/#POINTCLOUD_VERSION_MAJOR#/$(EXTVERSION_MAJOR)/' $< > $@

$(EXTENSION)--$(EXTVERSION).sql: $(EXTENSION).sql.in Makefile
$(SQLPP) -I. $< | $(SED) -e 's/#POINTCLOUD_VERSION#/$(EXTVERSION)/' > $@

# NOTE: relies on PERL being defined by PGXS
$(EXTENSION)--%--$(EXTVERSION).sql: $(EXTENSION)--$(EXTVERSION).sql ../util/proc_upgrade.pl
cat $< | ../util/proc_upgrade.pl > $@

$(EXTENSION)--%--$(EXTVERSION)next.sql: $(EXTENSION)--$(EXTVERSION)next--$(EXTVERSION).sql
ln -f $< $@
Loading

0 comments on commit 38011ac

Please sign in to comment.