diff --git a/lib/cunit/cu_pc_schema.c b/lib/cunit/cu_pc_schema.c index 76abdd4..54034ad 100644 --- a/lib/cunit/cu_pc_schema.c +++ b/lib/cunit/cu_pc_schema.c @@ -201,13 +201,17 @@ test_schema_clone(void) CU_ASSERT_EQUAL(clone->ndims, schema->ndims); CU_ASSERT_EQUAL(clone->size, schema->size); CU_ASSERT_EQUAL(clone->srid, schema->srid); - CU_ASSERT_EQUAL(clone->x_position, schema->x_position); - CU_ASSERT_EQUAL(clone->y_position, schema->y_position); - CU_ASSERT_EQUAL(clone->z_position, schema->z_position); - CU_ASSERT_EQUAL(clone->m_position, schema->m_position); + CU_ASSERT_EQUAL(clone->xdim->position, schema->xdim->position); + CU_ASSERT_EQUAL(clone->ydim->position, schema->ydim->position); + CU_ASSERT_EQUAL(clone->zdim->position, schema->zdim->position); + CU_ASSERT_EQUAL(clone->mdim->position, schema->mdim->position); CU_ASSERT_EQUAL(clone->compression, schema->compression); - CU_ASSERT(clone->dims != schema->dims); /* deep clone */ - CU_ASSERT(clone->namehash != schema->namehash); /* deep clone */ + CU_ASSERT_NOT_EQUAL(clone->xdim, schema->xdim); /* deep clone */ + CU_ASSERT_NOT_EQUAL(clone->ydim, schema->ydim); /* deep clone */ + CU_ASSERT_NOT_EQUAL(clone->zdim, schema->zdim); /* deep clone */ + CU_ASSERT_NOT_EQUAL(clone->mdim, schema->mdim); /* deep clone */ + CU_ASSERT_NOT_EQUAL(clone->dims, schema->dims); /* deep clone */ + CU_ASSERT_NOT_EQUAL(clone->namehash, schema->namehash); /* deep clone */ hash = schema->namehash; chash = clone->namehash; CU_ASSERT_EQUAL(chash->tablelength, hash->tablelength); diff --git a/lib/pc_api.h b/lib/pc_api.h index f5b4878..94c3d1a 100644 --- a/lib/pc_api.h +++ b/lib/pc_api.h @@ -88,10 +88,10 @@ typedef struct size_t size; /* How wide (bytes) is a point with this schema? */ PCDIMENSION **dims; /* Array of dimension pointers */ uint32_t srid; /* Foreign key reference to SPATIAL_REF_SYS */ - int32_t x_position; /* What entry is the x coordinate at? */ - int32_t y_position; /* What entry is the y coordinate at? */ - int32_t z_position; /* What entry is the z coordinate at? */ - int32_t m_position; /* What entry is the m coordinate at? */ + PCDIMENSION *xdim; /* pointer to the x dimension within dims */ + PCDIMENSION *ydim; /* pointer to the y dimension within dims */ + PCDIMENSION *zdim; /* pointer to the z dimension within dims */ + PCDIMENSION *mdim; /* pointer to the m dimension within dims */ uint32_t compression; /* Compression type applied to the data */ hashtable *namehash; /* Look-up from dimension name to pointer */ } PCSCHEMA; diff --git a/lib/pc_filter.c b/lib/pc_filter.c index 950b052..4d353c8 100644 --- a/lib/pc_filter.c +++ b/lib/pc_filter.c @@ -166,12 +166,12 @@ pc_patch_dimensional_filter(const PCPATCH_DIMENSIONAL *pdl, const PCBITMAP *map) stats.sum = pc_value_scale_offset(stats.sum, dim); /* Save the X/Y stats for use in bounds later */ - if ( i == pdl->schema->x_position ) + if ( dim == pdl->schema->xdim ) { fpdl->bounds.xmin = stats.min; fpdl->bounds.xmax = stats.max; } - else if ( i == pdl->schema->y_position ) + else if ( dim == pdl->schema->ydim ) { fpdl->bounds.ymin = stats.min; fpdl->bounds.ymax = stats.max; diff --git a/lib/pc_patch_dimensional.c b/lib/pc_patch_dimensional.c index 840f44b..01ac1cb 100644 --- a/lib/pc_patch_dimensional.c +++ b/lib/pc_patch_dimensional.c @@ -185,22 +185,24 @@ pc_patch_dimensional_compute_extent(PCPATCH_DIMENSIONAL *pdl) assert(pdl); assert(pdl->schema); + assert(pdl->schema->xdim); + assert(pdl->schema->ydim); /* Get x extremes */ - pcb = &(pdl->bytes[pdl->schema->x_position]); + pcb = &(pdl->bytes[pdl->schema->xdim->position]); rv = pc_bytes_minmax(pcb, &xmin, &xmax, &xavg); if ( PC_FAILURE == rv ) return PC_FAILURE; - xmin = pc_value_scale_offset(xmin, pdl->schema->dims[pdl->schema->x_position]); - xmax = pc_value_scale_offset(xmax, pdl->schema->dims[pdl->schema->x_position]); + xmin = pc_value_scale_offset(xmin, pdl->schema->xdim); + xmax = pc_value_scale_offset(xmax, pdl->schema->xdim); pdl->bounds.xmin = xmin; pdl->bounds.xmax = xmax; /* Get y extremes */ - pcb = &(pdl->bytes[pdl->schema->y_position]); + pcb = &(pdl->bytes[pdl->schema->ydim->position]); rv = pc_bytes_minmax(pcb, &ymin, &ymax, &yavg); if ( PC_FAILURE == rv ) return PC_FAILURE; - ymin = pc_value_scale_offset(ymin, pdl->schema->dims[pdl->schema->y_position]); - ymax = pc_value_scale_offset(ymax, pdl->schema->dims[pdl->schema->y_position]); + ymin = pc_value_scale_offset(ymin, pdl->schema->ydim); + ymax = pc_value_scale_offset(ymax, pdl->schema->ydim); pdl->bounds.ymin = ymin; pdl->bounds.ymax = ymax; diff --git a/lib/pc_point.c b/lib/pc_point.c index a9de6fa..42ea39b 100644 --- a/lib/pc_point.c +++ b/lib/pc_point.c @@ -143,50 +143,50 @@ pc_point_set_double_by_name(PCPOINT *pt, const char *name, double val) int pc_point_get_x(const PCPOINT *pt, double *val) { - return pc_point_get_double_by_index(pt, pt->schema->x_position, val); + return pc_point_get_double(pt, pt->schema->xdim, val); } int pc_point_get_y(const PCPOINT *pt, double *val) { - return pc_point_get_double_by_index(pt, pt->schema->y_position, val); + return pc_point_get_double(pt, pt->schema->ydim, val); } int pc_point_get_z(const PCPOINT *pt, double *val) { - return pc_point_get_double_by_index(pt, pt->schema->z_position, val); + return pc_point_get_double(pt, pt->schema->zdim, val); } int pc_point_get_m(const PCPOINT *pt, double *val) { - return pc_point_get_double_by_index(pt, pt->schema->m_position, val); + return pc_point_get_double(pt, pt->schema->mdim, val); } int pc_point_set_x(PCPOINT *pt, double val) { - return pc_point_set_double_by_index(pt, pt->schema->x_position, val); + return pc_point_set_double(pt, pt->schema->xdim, val); } int pc_point_set_y(PCPOINT *pt, double val) { - return pc_point_set_double_by_index(pt, pt->schema->y_position, val); + return pc_point_set_double(pt, pt->schema->ydim, val); } int pc_point_set_z(PCPOINT *pt, double val) { - return pc_point_set_double_by_index(pt, pt->schema->z_position, val); + return pc_point_set_double(pt, pt->schema->zdim, val); } int pc_point_set_m(PCPOINT *pt, double val) { - return pc_point_set_double_by_index(pt, pt->schema->m_position, val); + return pc_point_set_double(pt, pt->schema->mdim, val); } char * diff --git a/lib/pc_schema.c b/lib/pc_schema.c index b900410..e56f6dd 100644 --- a/lib/pc_schema.c +++ b/lib/pc_schema.c @@ -196,10 +196,7 @@ pc_schema_new(uint32_t ndims) pcs->dims = pcalloc(sizeof(PCDIMENSION*) * ndims); pcs->namehash = create_string_hashtable(); pcs->ndims = ndims; - pcs->x_position = -1; - pcs->y_position = -1; - pcs->z_position = -1; - pcs->m_position = -1; + /* pcalloc memsets to 0, so xdim,ydim,zdim and mdim are already NULL */ return pcs; } @@ -237,10 +234,6 @@ pc_schema_clone(const PCSCHEMA *s) PCSCHEMA *pcs = pc_schema_new(s->ndims); pcs->pcid = s->pcid; pcs->srid = s->srid; - pcs->x_position = s->x_position; - pcs->y_position = s->y_position; - pcs->z_position = s->z_position; - pcs->m_position = s->m_position; pcs->compression = s->compression; for ( i = 0; i < pcs->ndims; i++ ) { @@ -249,6 +242,10 @@ pc_schema_clone(const PCSCHEMA *s) pc_schema_set_dimension(pcs, pc_dimension_clone(s->dims[i])); } } + pcs->xdim = s->xdim ? pcs->dims[s->xdim->position] : NULL; + pcs->ydim = s->ydim ? pcs->dims[s->ydim->position] : NULL; + pcs->zdim = s->zdim ? pcs->dims[s->zdim->position] : NULL; + pcs->mdim = s->mdim ? pcs->dims[s->mdim->position] : NULL; pc_schema_calculate_byteoffsets(pcs); return pcs; } @@ -341,21 +338,21 @@ void pc_schema_check_xyzm(PCSCHEMA *s) strcasecmp(dimname, "Longitude") == 0 || strcasecmp(dimname, "Lon") == 0 ) { - s->x_position = i; + s->xdim = s->dims[i]; continue; } if ( strcasecmp(dimname, "Y") == 0 || strcasecmp(dimname, "Latitude") == 0 || strcasecmp(dimname, "Lat") == 0 ) { - s->y_position = i; + s->ydim = s->dims[i]; continue; } if ( strcasecmp(dimname, "Z") == 0 || strcasecmp(dimname, "H") == 0 || strcasecmp(dimname, "Height") == 0 ) { - s->z_position = i; + s->zdim = s->dims[i]; continue; } if ( strcasecmp(dimname, "M") == 0 || @@ -363,7 +360,7 @@ void pc_schema_check_xyzm(PCSCHEMA *s) strcasecmp(dimname, "Time") == 0 || strcasecmp(dimname, "GPSTime") == 0 ) { - s->m_position = i; + s->mdim = s->dims[i]; continue; } } @@ -584,13 +581,13 @@ pc_schema_is_valid(const PCSCHEMA *s) { int i; - if ( s->x_position < 0 ) + if ( ! s->xdim ) { pcwarn("schema does not include an X coordinate"); return PC_FALSE; } - if ( s->y_position < 0 ) + if ( ! s->ydim ) { pcwarn("schema does not include a Y coordinate"); return PC_FALSE;