int
pc_patch_uncompressed_compute_extent(PCPATCH_UNCOMPRESSED *patch)
{
	int i;
	PCPOINT *pt = pc_point_from_data(patch->schema, patch->data);
	PCBOUNDS b;
	double x, y;

	/* Calculate bounds */
	pc_bounds_init(&b);
	for ( i = 0; i < patch->npoints; i++ )
	{
		/* Just push the data buffer forward by one point at a time */
		pt->data = patch->data + i * patch->schema->size;
		x = pc_point_get_x(pt);
		y = pc_point_get_y(pt);
		if ( b.xmin > x ) b.xmin = x;
		if ( b.ymin > y ) b.ymin = y;
		if ( b.xmax < x ) b.xmax = x;
		if ( b.ymax < y ) b.ymax = y;
	}

	patch->bounds = b;
	pcfree(pt);
	return PC_SUCCESS;
}
示例#2
0
uint8_t *
pc_point_to_geometry_wkb(const PCPOINT *pt, size_t *wkbsize)
{
	static uint32_t srid_mask = 0x20000000;
	static uint32_t z_mask = 0x80000000;
	uint32_t wkbtype = 1; /* WKB POINT */
	size_t size = 1 + 4 + 8 + 8; /* endian + type + dblX, + dblY */
	uint8_t *wkb, *ptr;
	uint32_t srid;
	int has_srid = PC_FALSE, has_z = PC_FALSE;
	double x, y, z;

	x = pc_point_get_x(pt);
	y = pc_point_get_y(pt);

	if ( pt->schema->srid > 0 )
	{
		has_srid = PC_TRUE;
		wkbtype |= srid_mask;
		size += 4;
		srid = pt->schema->srid;
	}

	if ( pc_point_get_double_by_name(pt, "Z", &z) )
	{
		has_z = PC_TRUE;
		wkbtype |= z_mask;
		size += 8;
	}

	wkb = pcalloc(size);
	ptr = wkb;

	ptr[0] = machine_endian(); /* Endian flag */
	ptr += 1;

	memcpy(ptr, &wkbtype, 4); /* WKB type */
	ptr += 4;

	if ( has_srid )
	{
		memcpy(ptr, &srid, 4); /* SRID */
		ptr += 4;
	}

	memcpy(ptr, &x, 8); /* X */
	ptr += 8;

	memcpy(ptr, &y, 8); /* Y */
	ptr += 8;

	if ( has_z )
	{
		memcpy(ptr, &z, 8); /* Z */
		ptr += 8;
	}

	if ( wkbsize ) *wkbsize = size;
	return wkb;
}
int
pc_patch_uncompressed_add_point(PCPATCH_UNCOMPRESSED *c, const PCPOINT *p)
{
	size_t sz;
	uint8_t *ptr;
	double x, y;

	if ( ! ( c && p ) )
	{
		pcerror("%s: null point or patch argument", __func__);
		return PC_FAILURE;
	}

	if ( c->schema->pcid != p->schema->pcid )
	{
		pcerror("%s: pcids of point (%d) and patch (%d) not equal", __func__, c->schema->pcid, p->schema->pcid);
		return PC_FAILURE;
	}

	if ( c->readonly )
	{
		pcerror("%s: cannot add point to readonly patch", __func__);
		return PC_FAILURE;
	}

	if ( c->type != PC_NONE )
	{
		pcerror("%s: cannot add point to compressed patch", __func__);
		return PC_FAILURE;
	}

	sz = c->schema->size;

	/* Double the data buffer if it's already full */
	if ( c->npoints == c->maxpoints )
	{
		c->maxpoints *= 2;
		c->datasize = c->maxpoints * sz;
		c->data = pcrealloc(c->data, c->datasize);
	}

	/* Copy the data buffer from point to patch */
	ptr = c->data + sz * c->npoints;
	memcpy(ptr, p->data, sz);
	c->npoints += 1;

	/* Update bounding box */
	x = pc_point_get_x(p);
	y = pc_point_get_y(p);
	if ( c->bounds.xmin > x ) c->bounds.xmin = x;
	if ( c->bounds.ymin > y ) c->bounds.ymin = y;
	if ( c->bounds.xmax < x ) c->bounds.xmax = x;
	if ( c->bounds.ymax < y ) c->bounds.ymax = y;

	return PC_SUCCESS;
}
示例#4
0
static void
test_point_xyzm()
{
	PCPOINT *pt;
	double x = 1;
	double y = 40;
	double z = 160;
	double m = 640;
	double d;

	pt = pc_point_make(schema_xyz);
	CU_ASSERT_PTR_NOT_NULL( pt );

	CU_ASSERT_SUCCESS(pc_point_set_x(pt, x));
	CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "X", &d));
	CU_ASSERT_DOUBLE_EQUAL(d, x, 0.000001);
	CU_ASSERT_SUCCESS(pc_point_get_x(pt, &d));
	CU_ASSERT_DOUBLE_EQUAL(d, x, 0.000001);

	CU_ASSERT_SUCCESS(pc_point_set_y(pt, y));
	CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "Y", &d));
	CU_ASSERT_DOUBLE_EQUAL(d, y, 0.000001);
	CU_ASSERT_SUCCESS(pc_point_get_y(pt, &d));
	CU_ASSERT_DOUBLE_EQUAL(d, y, 0.000001);

	CU_ASSERT_SUCCESS(pc_point_set_z(pt, z));
	CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "Z", &d));
	CU_ASSERT_DOUBLE_EQUAL(d, z, 0.000001);
	CU_ASSERT_SUCCESS(pc_point_get_z(pt, &d));
	CU_ASSERT_DOUBLE_EQUAL(d, z, 0.000001);

	CU_ASSERT_FAILURE(pc_point_set_m(pt, m));
	CU_ASSERT_FAILURE(pc_point_get_double_by_name(pt, "M", &d));
	CU_ASSERT_FAILURE(pc_point_get_m(pt, &d));

	pc_point_free(pt);

	pt = pc_point_make(schema_xyzm);
	CU_ASSERT_PTR_NOT_NULL( pt );

	CU_ASSERT_SUCCESS(pc_point_set_x(pt, x));
	CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "X", &d));
	CU_ASSERT_DOUBLE_EQUAL(d, x, 0.000001);
	CU_ASSERT_SUCCESS(pc_point_get_x(pt, &d));
	CU_ASSERT_DOUBLE_EQUAL(d, x, 0.000001);

	CU_ASSERT_SUCCESS(pc_point_set_y(pt, y));
	CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "Y", &d));
	CU_ASSERT_DOUBLE_EQUAL(d, y, 0.000001);
	CU_ASSERT_SUCCESS(pc_point_get_y(pt, &d));
	CU_ASSERT_DOUBLE_EQUAL(d, y, 0.000001);

	CU_ASSERT_SUCCESS(pc_point_set_z(pt, z));
	CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "Z", &d));
	CU_ASSERT_DOUBLE_EQUAL(d, z, 0.000001);
	CU_ASSERT_SUCCESS(pc_point_get_z(pt, &d));
	CU_ASSERT_DOUBLE_EQUAL(d, z, 0.000001);

	CU_ASSERT_SUCCESS(pc_point_set_m(pt, m));
	CU_ASSERT_SUCCESS(pc_point_get_double_by_name(pt, "M", &d));
	CU_ASSERT_DOUBLE_EQUAL(d, m, 0.000001);
	CU_ASSERT_SUCCESS(pc_point_get_m(pt, &d));
	CU_ASSERT_DOUBLE_EQUAL(d, m, 0.000001);

	pc_point_free(pt);
}
示例#5
0
uint8_t *
pc_point_to_geometry_wkb(const PCPOINT *pt, size_t *wkbsize)
{
	static uint32_t srid_mask = 0x20000000;
	static uint32_t m_mask = 0x40000000;
	static uint32_t z_mask = 0x80000000;
	uint32_t wkbtype = 1; /* WKB POINT */
	size_t size = 1 + 4 + 8 + 8; /* endian + type + dblX, + dblY */
	uint8_t *wkb, *ptr;
	uint32_t srid = pt->schema->srid;
	double x, y, z, m;
	int has_x = pc_point_get_x(pt, &x) == PC_SUCCESS;
	int has_y = pc_point_get_y(pt, &y) == PC_SUCCESS;
	int has_z = pc_point_get_z(pt, &z) == PC_SUCCESS;
	int has_m = pc_point_get_m(pt, &m) == PC_SUCCESS;

	if ( ! ( has_x && has_y ) )
		return NULL;

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

	if ( has_z )
	{
		wkbtype |= z_mask;
		size += 8;
	}

	if ( has_m )
	{
		wkbtype |= m_mask;
		size += 8;
	}

	wkb = pcalloc(size);
	ptr = wkb;

	ptr[0] = machine_endian(); /* Endian flag */
	ptr += 1;

	memcpy(ptr, &wkbtype, 4); /* WKB type */
	ptr += 4;

	if ( srid != 0 )
	{
		memcpy(ptr, &srid, 4); /* SRID */
		ptr += 4;
	}

	memcpy(ptr, &x, 8); /* X */
	ptr += 8;

	memcpy(ptr, &y, 8); /* Y */
	ptr += 8;

	if ( has_z )
	{
		memcpy(ptr, &z, 8); /* Z */
		ptr += 8;
	}

	if ( has_m )
	{
		memcpy(ptr, &m, 8); /* M */
		ptr += 8;
	}

	if ( wkbsize ) *wkbsize = size;
	return wkb;
}