//-----------------------------------------------------------------
+typedef unsigned char uchar;
+
typedef struct
{
float xmin;
// DONT MIX 2D and 3D POINTS! *EVERYTHING* is either one or the other
typedef struct
{
- char *serialized_pointlist; // array of POINT 2D, 3D or 4D.
- // probably missaligned.
- // points to a double
- unsigned char dims; // use TYPE_* macros to handle
+ /* array of POINT 2D, 3D or 4D. probably missaligned. */
+ uchar *serialized_pointlist;
+
+ /* use TYPE_* macros to handle */
+ uchar dims;
+
uint32 npoints;
} POINTARRAY;
// LWGEOM (any type)
typedef struct
{
- unsigned char type;
+ uchar type;
BOX2DFLOAT4 *bbox;
uint32 SRID; // -1 == unneeded
void *data;
// POINTYPE
typedef struct
{
- unsigned char type; // POINTTYPE
+ uchar type; // POINTTYPE
BOX2DFLOAT4 *bbox;
uint32 SRID;
POINTARRAY *point; // hide 2d/3d (this will be an array of 1 point)
// LINETYPE
typedef struct
{
- unsigned char type; // LINETYPE
+ uchar type; // LINETYPE
BOX2DFLOAT4 *bbox;
uint32 SRID;
POINTARRAY *points; // array of POINT3D
// POLYGONTYPE
typedef struct
{
- unsigned char type; // POLYGONTYPE
+ uchar type; // POLYGONTYPE
BOX2DFLOAT4 *bbox;
uint32 SRID;
int nrings;
// MULTIPOINTTYPE
typedef struct
{
- unsigned char type;
+ uchar type;
BOX2DFLOAT4 *bbox;
uint32 SRID;
int ngeoms;
// MULTILINETYPE
typedef struct
{
- unsigned char type;
+ uchar type;
BOX2DFLOAT4 *bbox;
uint32 SRID;
int ngeoms;
// MULTIPOLYGONTYPE
typedef struct
{
- unsigned char type;
+ uchar type;
BOX2DFLOAT4 *bbox;
uint32 SRID;
int ngeoms;
// COLLECTIONTYPE
typedef struct
{
- unsigned char type;
+ uchar type;
BOX2DFLOAT4 *bbox;
uint32 SRID;
int ngeoms;
// You'll need to cast it to appropriate dimensioned point.
// Note that if you cast to a higher dimensional point you'll
// possibly corrupt the POINTARRAY.
-extern char *getPoint(const POINTARRAY *pa, int n);
+extern uchar *getPoint(const POINTARRAY *pa, int n);
//--- here is a macro equivalent, for speed...
//#define getPoint(x,n) &( (x)->serialized_pointlist[((x)->ndims*8)*(n)] )
// NOTE: points is *not* copied, so be careful about modification (can be aligned/missaligned)
// NOTE: hasz and hasm are descriptive - it describes what type of data
// 'points' points to. No data conversion is done.
-extern POINTARRAY *pointArray_construct(char *points, char hasz, char hasm, uint32 npoints);
+extern POINTARRAY *pointArray_construct(uchar *points, char hasz, char hasm, uint32 npoints);
//calculate the bounding box of a set of points
// returns a 3d box
#define TYPE_GETTYPE(t) ((t)&0x0F)
#define TYPE_GETZM(t) (((t)&0x30)>>4)
-extern char lwgeom_hasBBOX(unsigned char type); // true iff B bit set
-extern int lwgeom_ndims(unsigned char type); // returns 2,3 or 4
-extern int lwgeom_hasZ(unsigned char type); // has Z ?
-extern int lwgeom_hasM(unsigned char type); // has M ?
-extern int lwgeom_getType(unsigned char type); // returns the tttt value
+extern char lwgeom_hasBBOX(uchar type); // true iff B bit set
+extern int lwgeom_ndims(uchar type); // returns 2,3 or 4
+extern int lwgeom_hasZ(uchar type); // has Z ?
+extern int lwgeom_hasM(uchar type); // has M ?
+extern int lwgeom_getType(uchar type); // returns the tttt value
-extern unsigned char lwgeom_makeType(char hasZ, char hasM, char hasSRID, int type);
-extern unsigned char lwgeom_makeType_full(char hasZ, char hasM, char hasSRID, int type, char hasBBOX);
-extern char lwgeom_hasSRID(unsigned char type); // true iff S bit is set
-extern char lwgeom_hasBBOX(unsigned char type); // true iff B bit set
+extern uchar lwgeom_makeType(char hasZ, char hasM, char hasSRID, int type);
+extern uchar lwgeom_makeType_full(char hasZ, char hasM, char hasSRID, int type, char hasBBOX);
+extern char lwgeom_hasSRID(uchar type); // true iff S bit is set
+extern char lwgeom_hasBBOX(uchar type); // true iff B bit set
*/
typedef struct {
uint32 size;
- unsigned char type; // encodes ndims, type, bbox presence,
+ uchar type; // encodes ndims, type, bbox presence,
// srid presence
- char data[1];
+ uchar data[1];
} PG_LWGEOM;
/*
* If you request bbox (wantbbox=1) it will be extracted or computed
* from the serialized form.
*/
-extern PG_LWGEOM *PG_LWGEOM_construct(char *serialized, int SRID, int wantbbox);
+extern PG_LWGEOM *PG_LWGEOM_construct(uchar *serialized, int SRID, int wantbbox);
/*
* Compute bbox of serialized geom
*/
-extern int compute_serialized_bbox_p(char *serialized_form, BOX2DFLOAT4 *box);
+extern int compute_serialized_bbox_p(uchar *serialized_form, BOX2DFLOAT4 *box);
/*
* caching a bbox
*/
char is_worth_caching_pglwgeom_bbox(const PG_LWGEOM *);
-char is_worth_caching_serialized_bbox(const char *);
+char is_worth_caching_serialized_bbox(const uchar *);
char is_worth_caching_lwgeom_bbox(const LWGEOM *);
/*
* by most functions from an PG_LWGEOM struct.
* (which is an PG_LWGEOM w/out int32 size casted to char *)
*/
-#define SERIALIZED_FORM(x) ((char *)(x))+4
+#define SERIALIZED_FORM(x) ((uchar *)(x))+4
/*
* This function computes the size in bytes
* of the serialized geometries.
*/
-extern size_t lwgeom_size(const char *serialized_form);
-extern size_t lwgeom_size_subgeom(const char *serialized_form, int geom_number);
-extern size_t lwgeom_size_line(const char *serialized_line);
-extern size_t lwgeom_size_point(const char *serialized_point);
-extern size_t lwgeom_size_poly(const char *serialized_line);
+extern size_t lwgeom_size(const uchar *serialized_form);
+extern size_t lwgeom_size_subgeom(const uchar *serialized_form, int geom_number);
+extern size_t lwgeom_size_line(const uchar *serialized_line);
+extern size_t lwgeom_size_point(const uchar *serialized_point);
+extern size_t lwgeom_size_poly(const uchar *serialized_line);
//--------------------------------------------------------
// serialized_form should point to the 8bit type format (with type = 1)
// Returns NULL if serialized form is not a point.
// See serialized form doc
-extern LWPOINT *lwpoint_deserialize(char *serialized_form);
+extern LWPOINT *lwpoint_deserialize(uchar *serialized_form);
// Find size this point would get when serialized (no BBOX)
extern size_t lwpoint_serialize_size(LWPOINT *point);
// convert this point into its serialize form
// result's first char will be the 8bit type. See serialized form doc
-extern char *lwpoint_serialize(LWPOINT *point);
+extern uchar *lwpoint_serialize(LWPOINT *point);
// same as above, writes to buf
-extern void lwpoint_serialize_buf(LWPOINT *point, char *buf, size_t *size);
+extern void lwpoint_serialize_buf(LWPOINT *point, uchar *buf, size_t *size);
// find bounding box (standard one) zmin=zmax=0 if 2d (might change to NaN)
extern BOX3D *lwpoint_findbbox(LWPOINT *point);
// construct a proper LWLINE.
// serialized_form should point to the 8bit type format (with type = 2)
// See serialized form doc
-extern LWLINE *lwline_deserialize(char *serialized_form);
+extern LWLINE *lwline_deserialize(uchar *serialized_form);
// find the size this line would get when serialized (no BBOX)
extern size_t lwline_serialize_size(LWLINE *line);
// convert this line into its serialize form
// result's first char will be the 8bit type. See serialized form doc
// copies data.
-extern char *lwline_serialize(LWLINE *line);
+extern uchar *lwline_serialize(LWLINE *line);
// same as above, writes to buf
-extern void lwline_serialize_buf(LWLINE *line, char *buf, size_t *size);
+extern void lwline_serialize_buf(LWLINE *line, uchar *buf, size_t *size);
// find bounding box (standard one) zmin=zmax=0 if 2d (might change to NaN)
extern BOX3D *lwline_findbbox(LWLINE *line);
// construct a proper LWPOLY.
// serialized_form should point to the 8bit type format (with type = 3)
// See serialized form doc
-extern LWPOLY *lwpoly_deserialize(char *serialized_form);
+extern LWPOLY *lwpoly_deserialize(uchar *serialized_form);
// find the size this polygon would get when serialized (no bbox!)
extern size_t lwpoly_serialize_size(LWPOLY *poly);
// create the serialized form of the polygon
// result's first char will be the 8bit type. See serialized form doc
// points copied
-extern char *lwpoly_serialize(LWPOLY *poly);
+extern uchar *lwpoly_serialize(LWPOLY *poly);
// same as above, writes to buf
-extern void lwpoly_serialize_buf(LWPOLY *poly, char *buf, size_t *size);
+extern void lwpoly_serialize_buf(LWPOLY *poly, uchar *buf, size_t *size);
// find bounding box (standard one) zmin=zmax=0 if 2d (might change to NaN)
extern BOX3D *lwpoly_findbbox(LWPOLY *poly);
extern size_t lwgeom_serialize_size(LWGEOM *geom);
extern size_t lwcollection_serialize_size(LWCOLLECTION *coll);
-extern void lwgeom_serialize_buf(LWGEOM *geom, char *buf, size_t *size);
-extern char *lwgeom_serialize(LWGEOM *geom);
-extern void lwcollection_serialize_buf(LWCOLLECTION *mcoll, char *buf, size_t *size);
+extern void lwgeom_serialize_buf(LWGEOM *geom, uchar *buf, size_t *size);
+extern uchar *lwgeom_serialize(LWGEOM *geom);
+extern void lwcollection_serialize_buf(LWCOLLECTION *mcoll, uchar *buf, size_t *size);
//-----------------------------------------------------
// Deserialize an lwgeom serialized form.
// The deserialized (recursive) structure will store
// pointers to the serialized form (POINTARRAYs).
-LWGEOM *lwgeom_deserialize(char *serializedform);
+LWGEOM *lwgeom_deserialize(uchar *serializedform);
// Release memory associated with LWGEOM.
// POINTARRAYs are not released as they are usually
// pointers to user-managed memory.
void lwgeom_release(LWGEOM *lwgeom);
-LWMPOINT *lwmpoint_deserialize(char *serializedform);
-LWMLINE *lwmline_deserialize(char *serializedform);
-LWMPOLY *lwmpoly_deserialize(char *serializedform);
-LWCOLLECTION *lwcollection_deserialize(char *serializedform);
+LWMPOINT *lwmpoint_deserialize(uchar *serializedform);
+LWMLINE *lwmline_deserialize(uchar *serializedform);
+LWMPOLY *lwmpoly_deserialize(uchar *serializedform);
+LWCOLLECTION *lwcollection_deserialize(uchar *serializedform);
LWGEOM *lwcollection_getsubgeom(LWCOLLECTION *, int);
typedef struct
{
int SRID;
- const char *serialized_form; // orginal structure
- unsigned char type; // 8-bit type for the LWGEOM
+ const uchar *serialized_form; // orginal structure
+ uchar type; // 8-bit type for the LWGEOM
int ngeometries; // number of sub-geometries
- char **sub_geoms; // list of pointers (into serialized_form) of the sub-geoms
+ uchar **sub_geoms; // list of pointers (into serialized_form) of the sub-geoms
} LWGEOM_INSPECTED;
extern int lwgeom_size_inspected(const LWGEOM_INSPECTED *inspected, int geom_number);
typedef struct
{
int SRID;
- unsigned char dims;
+ uchar dims;
uint32 npoints;
- char **points;
+ uchar **points;
uint32 nlines;
- char **lines;
+ uchar **lines;
uint32 npolys;
- char **polys;
+ uchar **polys;
} LWGEOM_EXPLODED;
void pfree_exploded(LWGEOM_EXPLODED *exploded);
* This function recursively scan the given serialized geometry
* and returns a list of _all_ subgeoms in it (deep-first)
*/
-extern LWGEOM_EXPLODED *lwgeom_explode(char *serialized);
+extern LWGEOM_EXPLODED *lwgeom_explode(uchar *serialized);
/*
* Return the length of the serialized form corresponding
// Serialize an LWGEOM_EXPLODED object.
// SRID and ndims will be taken from exploded structure.
// wantbbox will determine result bbox.
-extern char *lwexploded_serialize(LWGEOM_EXPLODED *exploded, int wantbbox);
+extern uchar *lwexploded_serialize(LWGEOM_EXPLODED *exploded, int wantbbox);
// Same as lwexploded_serialize but writing to pre-allocated space
-extern void lwexploded_serialize_buf(LWGEOM_EXPLODED *exploded, int wantbbox, char *buf, size_t *retsize);
+extern void lwexploded_serialize_buf(LWGEOM_EXPLODED *exploded, int wantbbox, uchar *buf, size_t *retsize);
// note - for a simple type (ie. point), this will have sub_geom[0] = serialized_form.
// for multi-geomtries sub_geom[0] will be a few bytes into the serialized form
// This function just computes the length of each sub-object and pre-caches this info.
// For a geometry collection of multi* geometries, you can inspect the sub-components
// as well.
-extern LWGEOM_INSPECTED *lwgeom_inspect(const char *serialized_form);
+extern LWGEOM_INSPECTED *lwgeom_inspect(const uchar *serialized_form);
// 1st geometry has geom_number = 0
// if the actual sub-geometry isnt a POINT, null is returned (see _gettype()).
// if there arent enough geometries, return null.
// this is fine to call on a point (with geom_num=0), multipoint or geometrycollection
-extern LWPOINT *lwgeom_getpoint(char *serialized_form, int geom_number);
+extern LWPOINT *lwgeom_getpoint(uchar *serialized_form, int geom_number);
extern LWPOINT *lwgeom_getpoint_inspected(LWGEOM_INSPECTED *inspected, int geom_number);
// 1st geometry has geom_number = 0
// if the actual geometry isnt a LINE, null is returned (see _gettype()).
// if there arent enough geometries, return null.
// this is fine to call on a line, multiline or geometrycollection
-extern LWLINE *lwgeom_getline(char *serialized_form, int geom_number);
+extern LWLINE *lwgeom_getline(uchar *serialized_form, int geom_number);
extern LWLINE *lwgeom_getline_inspected(LWGEOM_INSPECTED *inspected, int geom_number);
// 1st geometry has geom_number = 0
// if the actual geometry isnt a POLYGON, null is returned (see _gettype()).
// if there arent enough geometries, return null.
// this is fine to call on a polygon, multipolygon or geometrycollection
-extern LWPOLY *lwgeom_getpoly(char *serialized_form, int geom_number);
+extern LWPOLY *lwgeom_getpoly(uchar *serialized_form, int geom_number);
extern LWPOLY *lwgeom_getpoly_inspected(LWGEOM_INSPECTED *inspected, int geom_number);
// this gets the serialized form of a sub-geometry
// ie. lwgeom_getpoint( lwgeom_getsubgeometry( serialized, 0), 1)
// --> POINT(1 1)
// you can inspect the sub-geometry as well if you wish.
-extern char *lwgeom_getsubgeometry(const char *serialized_form, int geom_number);
-extern char *lwgeom_getsubgeometry_inspected(LWGEOM_INSPECTED *inspected, int geom_number);
+extern uchar *lwgeom_getsubgeometry(const uchar *serialized_form, int geom_number);
+extern uchar *lwgeom_getsubgeometry_inspected(LWGEOM_INSPECTED *inspected, int geom_number);
// 1st geometry has geom_number = 0
// ie lwgeom_gettype( <'MULTIPOINT(0 0, 1 1)'>, 0)
// --> point
// gets the 8bit type of the geometry at location geom_number
-extern char lwgeom_getsubtype(char *serialized_form, int geom_number);
-extern char lwgeom_getsubtype_inspected(LWGEOM_INSPECTED *inspected, int geom_number);
+extern uchar lwgeom_getsubtype(uchar *serialized_form, int geom_number);
+extern uchar lwgeom_getsubtype_inspected(LWGEOM_INSPECTED *inspected, int geom_number);
// how many sub-geometries are there?
// for point,line,polygon will return 1.
-extern int lwgeom_getnumgeometries(char *serialized_form);
+extern int lwgeom_getnumgeometries(uchar *serialized_form);
extern int lwgeom_getnumgeometries_inspected(LWGEOM_INSPECTED *inspected);
// use SRID=-1 for unknown SRID (will have 8bit type's S = 0)
// all subgeometries must have the same SRID
// if you want to construct an inspected, call this then inspect the result...
-extern char *lwgeom_serialized_construct(int SRID, int finalType, char hasz, char hasm, int nsubgeometries, char **serialized_subs);
+extern uchar *lwgeom_serialized_construct(int SRID, int finalType, char hasz, char hasm, int nsubgeometries, uchar **serialized_subs);
// construct the empty geometry (GEOMETRYCOLLECTION(EMPTY))
-extern char *lwgeom_constructempty(int SRID, char hasz, char hasm);
-extern void lwgeom_constructempty_buf(int SRID, char hasz, char hasm, char *buf, size_t *size);
+extern uchar *lwgeom_constructempty(int SRID, char hasz, char hasm);
+extern void lwgeom_constructempty_buf(int SRID, char hasz, char hasm, uchar *buf, size_t *size);
size_t lwgeom_empty_length(int SRID);
// get the SRID from the LWGEOM
// none present => -1
extern int pglwgeom_getSRID(PG_LWGEOM *lwgeom);
-extern int lwgeom_getsrid(char *serialized);
+extern int lwgeom_getsrid(uchar *serialized);
extern PG_LWGEOM *pglwgeom_setSRID(PG_LWGEOM *lwgeom, int32 newSRID);
//get bounding box of LWGEOM (automatically calls the sub-geometries bbox generators)
-extern BOX3D *lw_geom_getBB(char *serialized_form);
+extern BOX3D *lw_geom_getBB(uchar *serialized_form);
extern BOX3D *lw_geom_getBB_inspected(LWGEOM_INSPECTED *inspected);
// otherwise we need to compute it.
// WARNING! the EMPTY geom will result in a random BOX2D returned
// OBSOLETED for this reason
-//extern BOX2DFLOAT4 getbox2d(char *serialized_form);
+//extern BOX2DFLOAT4 getbox2d(uchar *serialized_form);
// Returns a pointer to the BBOX internal to the serialized form.
// READ-ONLY!
// Or NULL if serialized form does not have a BBOX
-extern BOX2DFLOAT4 *getbox2d_internal(char *serialized_form);
+extern BOX2DFLOAT4 *getbox2d_internal(uchar *serialized_form);
// this function writes to 'box' and returns 0 if serialized_form
// does not have a bounding box (empty geom)
-extern int getbox2d_p(char *serialized_form, BOX2DFLOAT4 *box);
+extern int getbox2d_p(uchar *serialized_form, BOX2DFLOAT4 *box);
// Expand given box of 'd' units in all directions
void expand_box2d(BOX2DFLOAT4 *box, double d);
//***********************************************************
// utility
-extern uint32 get_uint32(const char *loc);
-extern int32 get_int32(const char *loc);
+extern uint32 get_uint32(const uchar *loc);
+extern int32 get_int32(const uchar *loc);
extern void printPA(POINTARRAY *pa);
extern void printLWPOINT(LWPOINT *point);
extern void printLWLINE(LWLINE *line);
extern void printLWPOLY(LWPOLY *poly);
-extern void printBYTES(unsigned char *a, int n);
-extern void printMULTI(char *serialized);
-extern void printType(unsigned char str);
+extern void printBYTES(uchar *a, int n);
+extern void printMULTI(uchar *serialized);
+extern void printType(uchar str);
//------------------------------------------------------------
extern double lwgeom_polygon_perimeter2d(LWPOLY *poly);
extern double lwgeom_pointarray_length2d(POINTARRAY *pts);
extern double lwgeom_pointarray_length(POINTARRAY *pts);
-extern void lwgeom_force2d_recursive(char *serialized, char *optr, size_t *retsize);
-extern void lwgeom_force3dz_recursive(char *serialized, char *optr, size_t *retsize);
-extern void lwgeom_force3dm_recursive(unsigned char *serialized, char *optr, size_t *retsize);
-extern void lwgeom_force4d_recursive(char *serialized, char *optr, size_t *retsize);
+extern void lwgeom_force2d_recursive(uchar *serialized, uchar *optr, size_t *retsize);
+extern void lwgeom_force3dz_recursive(uchar *serialized, uchar *optr, size_t *retsize);
+extern void lwgeom_force3dm_recursive(uchar *serialized, uchar *optr, size_t *retsize);
+extern void lwgeom_force4d_recursive(uchar *serialized, uchar *optr, size_t *retsize);
extern double distance2d_pt_pt(POINT2D *p1, POINT2D *p2);
extern double distance2d_pt_seg(POINT2D *p, POINT2D *A, POINT2D *B);
extern double distance2d_seg_seg(POINT2D *A, POINT2D *B, POINT2D *C, POINT2D *D);
extern double distance2d_point_poly(LWPOINT *point, LWPOLY *poly);
extern double distance2d_poly_poly(LWPOLY *poly1, LWPOLY *poly2);
extern double distance2d_line_poly(LWLINE *line, LWPOLY *poly);
-extern double lwgeom_mindistance2d_recursive(char *lw1, char *lw2);
-extern void lwgeom_translate_recursive(char *serialized, double xoff, double yoff, double zoff);
+extern double lwgeom_mindistance2d_recursive(uchar *lw1, uchar *lw2);
+extern void lwgeom_translate_recursive(uchar *serialized, double xoff, double yoff, double zoff);
extern void lwgeom_translate_ptarray(POINTARRAY *pa, double xoff, double yoff, double zoff);
extern int lwgeom_pt_inside_circle(POINT2D *p, double cx, double cy, double rad);
-extern int32 lwgeom_npoints(char *serialized);
+extern int32 lwgeom_npoints(uchar *serialized);
extern char ptarray_isccw(const POINTARRAY *pa);
extern void lwgeom_reverse(LWGEOM *lwgeom);
extern void lwline_reverse(LWLINE *line);
extern LWPOLY *lwpoly_from_lwlines(const LWLINE *shell, unsigned int nholes, const LWLINE **holes);
// Return a char string with ASCII versionf of type flags
-extern const char *lwgeom_typeflags(unsigned char type);
+extern const uchar *lwgeom_typeflags(uchar type);
// Construct an empty pointarray
extern POINTARRAY *ptarray_construct(char hasz, char hasm, unsigned int npoints);
extern POINTARRAY *ptarray_construct3dz(uint32 npoints, const POINT3DZ *pts);
extern POINTARRAY *ptarray_construct3dm(uint32 npoints, const POINT3DM *pts);
extern POINTARRAY *ptarray_construct4d(uint32 npoints, const POINT4D *pts);
-extern POINTARRAY *ptarray_addPoint(POINTARRAY *pa, char *p, size_t pdims, unsigned int where);
+extern POINTARRAY *ptarray_addPoint(POINTARRAY *pa, uchar *p, size_t pdims, unsigned int where);
extern int ptarray_isclosed2d(const POINTARRAY *pa);
-extern int32 lwgeom_nrings_recursive(char *serialized);
+extern int32 lwgeom_nrings_recursive(uchar *serialized);
extern void dump_lwexploded(LWGEOM_EXPLODED *exploded);
extern void ptarray_reverse(POINTARRAY *pa);
extern LWPOLY *lwpoly_segmentize2d(LWPOLY *line, double dist);
extern LWCOLLECTION *lwcollection_segmentize2d(LWCOLLECTION *coll, double dist);
-extern unsigned char parse_hex(char *str);
-extern void deparse_hex(unsigned char str, unsigned char *result);
-extern char *parse_lwgeom_wkt(char *wkt_input);
+extern uchar parse_hex(char *str);
+extern void deparse_hex(uchar str, uchar *result);
+extern uchar *parse_lwgeom_wkt(char *wkt_input);
extern char *lwgeom_to_wkt(LWGEOM *lwgeom);
extern char *lwgeom_to_hexwkb(LWGEOM *lwgeom, unsigned int byteorder);
LWCOLLECTION *
-lwcollection_deserialize(char *srl)
+lwcollection_deserialize(uchar *srl)
{
LWCOLLECTION *result;
LWGEOM_INSPECTED *insp;
// the given buffer, and returning number of bytes written into
// the given int pointer.
void
-lwcollection_serialize_buf(LWCOLLECTION *coll, char *buf, size_t *retsize)
+lwcollection_serialize_buf(LWCOLLECTION *coll, uchar *buf, size_t *retsize)
{
size_t size=1; // type
size_t subsize=0;
char hasSRID;
- char *loc;
+ uchar *loc;
int i;
#ifdef PGIS_DEBUG_CALLS
hasSRID = (coll->SRID != -1);
- buf[0] = (unsigned char) lwgeom_makeType_full(
+ buf[0] = lwgeom_makeType_full(
TYPE_HASZ(coll->type), TYPE_HASM(coll->type),
hasSRID, TYPE_GETTYPE(coll->type), coll->bbox ? 1 : 0);
loc = buf+1;
lwcollection_same(const LWCOLLECTION *c1, const LWCOLLECTION *c2)
{
unsigned int i, j;
- char *hit;
+ unsigned int *hit;
#if PGIS_DEBUG_CALLS
lwnotice("lwcollection_same called");
if ( TYPE_GETTYPE(c1->type) != TYPE_GETTYPE(c2->type) ) return 0;
if ( c1->ngeoms != c2->ngeoms ) return 0;
- hit = (char *)lwalloc(sizeof(char)*c1->ngeoms);
- memset(hit, 0, sizeof(char)*c1->ngeoms);
+ hit = lwalloc(sizeof(unsigned int)*c1->ngeoms);
+ memset(hit, 0, sizeof(unsigned int)*c1->ngeoms);
for (i=0; i<c1->ngeoms; i++)
{
//#define PGIS_DEBUG_CALLS 1
LWGEOM *
-lwgeom_deserialize(char *srl)
+lwgeom_deserialize(uchar *srl)
{
int type = lwgeom_getType(srl[0]);
}
void
-lwgeom_serialize_buf(LWGEOM *lwgeom, char *buf, size_t *retsize)
+lwgeom_serialize_buf(LWGEOM *lwgeom, uchar *buf, size_t *retsize)
{
int type = TYPE_GETTYPE(lwgeom->type);
return;
}
-char *
+uchar *
lwgeom_serialize(LWGEOM *lwgeom)
{
size_t size = lwgeom_serialize_size(lwgeom);
size_t retsize;
- char *serialized = lwalloc(size);
+ uchar *serialized = lwalloc(size);
lwgeom_serialize_buf(lwgeom, serialized, &retsize);
char *
lwgeom_to_wkt(LWGEOM *lwgeom)
{
- char *serialized = lwgeom_serialize(lwgeom);
+ uchar *serialized = lwgeom_serialize(lwgeom);
char *ret;
if ( ! serialized ) {
lwerror("Error serializing geom %p", lwgeom);
char *
lwgeom_to_hexwkb(LWGEOM *lwgeom, unsigned int byteorder)
{
- char *serialized = lwgeom_serialize(lwgeom);
+ uchar *serialized = lwgeom_serialize(lwgeom);
char *hexwkb = unparse_WKB(serialized, lwalloc, lwfree, byteorder,NULL,1);
lwfree(serialized);
return hexwkb;
// This is an implementation of the functions defined in lwgeom.h
//forward decs
-extern BOX3D *lw_geom_getBB_simple(char *serialized_form);
+extern BOX3D *lw_geom_getBB_simple(uchar *serialized_form);
#ifdef PGIS_DEBUG_EXPLODED
-void checkexplodedsize(char *srl, LWGEOM_EXPLODED *exploded, int alloced, char wantbbox);
+void checkexplodedsize(uchar *srl, LWGEOM_EXPLODED *exploded, int alloced, char wantbbox);
#endif
-extern char *parse_lwg(const char* geometry, lwallocator allocfunc, lwreporter errfunc);
+extern uchar *parse_lwg(const char* geometry, lwallocator allocfunc, lwreporter errfunc);
//*********************************************************************
// BOX routines
// returns a pointer to internal storage, or NULL
// if the serialized form does not have a BBOX.
BOX2DFLOAT4 *
-getbox2d_internal(char *srl)
+getbox2d_internal(uchar *srl)
{
if (TYPE_HASBBOX(srl[0])) return (BOX2DFLOAT4 *)(srl+1);
else return NULL;
// same as getbox2d, but modifies box instead of returning result on the stack
int
-getbox2d_p(char *serialized_form, BOX2DFLOAT4 *box)
+getbox2d_p(uchar *serialized_form, BOX2DFLOAT4 *box)
{
- char type = serialized_form[0];
- char *loc;
+ uchar type = serialized_form[0];
+ uchar *loc;
BOX3D *box3d;
#ifdef PGIS_DEBUG
// You'll need to cast it to appropriate dimensioned point.
// Note that if you cast to a higher dimensional point you'll
// possibly corrupt the POINTARRAY.
-char *
+uchar *
getPoint(const POINTARRAY *pa, int n)
{
int size;
size = pointArray_ptsize(pa);
- // this does x,y
return &(pa->serialized_pointlist[size*n]);
}
// NOTE: ndims is descriptive - it describes what type of data 'points'
// points to. No data conversion is done.
POINTARRAY *
-pointArray_construct(char *points, char hasz, char hasm, uint32 npoints)
+pointArray_construct(uchar *points, char hasz, char hasm,
+ uint32 npoints)
{
POINTARRAY *pa;
pa = (POINTARRAY*)lwalloc(sizeof(POINTARRAY));
int
pointArray_ptsize(const POINTARRAY *pa)
{
+ //fprintf(stderr, "pointArray_ptsize: TYPE_NDIMS(pa->dims)=%x\n", TYPE_NDIMS(pa->dims));
return sizeof(double)*TYPE_NDIMS(pa->dims);
}
// returns true if this type says it has an SRID (S bit set)
char
-lwgeom_hasSRID(unsigned char type)
+lwgeom_hasSRID(uchar type)
{
return TYPE_HASSRID(type);
}
// returns either 2,3, or 4 -- 2=2D, 3=3D, 4=4D
int
-lwgeom_ndims(unsigned char type)
+lwgeom_ndims(uchar type)
{
return TYPE_NDIMS(type);
}
// has M ?
-int lwgeom_hasM(unsigned char type)
+int lwgeom_hasM(uchar type)
{
return ( (type & 0x10) >>4);
}
// has Z ?
-int lwgeom_hasZ(unsigned char type)
+int lwgeom_hasZ(uchar type)
{
return ( (type & 0x20) >>5);
}
// get base type (ie. POLYGONTYPE)
-int lwgeom_getType(unsigned char type)
+int
+lwgeom_getType(uchar type)
{
return (type & 0x0F);
}
//construct a type (hasBOX=false)
-unsigned char
+uchar
lwgeom_makeType(char hasz, char hasm, char hasSRID, int type)
{
return lwgeom_makeType_full(hasz, hasm, hasSRID, type, 0);
* Construct a type
* TODO: needs to be expanded to accept explicit MZ type
*/
-unsigned char
+uchar
lwgeom_makeType_full(char hasz, char hasm, char hasSRID, int type, char hasBBOX)
{
- unsigned char result = (char)type;
+ uchar result = (char)type;
TYPE_SETZM(result, hasz, hasm);
TYPE_SETHASSRID(result, hasSRID);
//returns true if there's a bbox in this LWGEOM (B bit set)
char
-lwgeom_hasBBOX(unsigned char type)
+lwgeom_hasBBOX(uchar type)
{
return TYPE_HASBBOX(type);
}
// handle missaligned unsigned int32 data
uint32
-get_uint32(const char *loc)
+get_uint32(const uchar *loc)
{
uint32 result;
// handle missaligned signed int32 data
int32
-get_int32(const char *loc)
+get_int32(const uchar *loc)
{
int32 result;
// For a geometry collection of multi* geometries, you can inspect the sub-components
// as well.
LWGEOM_INSPECTED *
-lwgeom_inspect(const char *serialized_form)
+lwgeom_inspect(const uchar *serialized_form)
{
LWGEOM_INSPECTED *result = lwalloc(sizeof(LWGEOM_INSPECTED));
- unsigned char typefl = (unsigned char)serialized_form[0];
- unsigned char type;
- char **sub_geoms;
- const char *loc;
+ uchar typefl = (uchar)serialized_form[0];
+ uchar type;
+ uchar **sub_geoms;
+ const uchar *loc;
int t;
#ifdef PGIS_DEBUG
return NULL;
result->serialized_form = serialized_form;
- result->type = (unsigned char) serialized_form[0];
+ result->type = (uchar) serialized_form[0];
result->SRID = -1; // assume
type = lwgeom_getType(typefl);
{
//simple geometry (point/line/polygon)-- not multi!
result->ngeometries = 1;
- sub_geoms = (char**) lwalloc(sizeof(char*));
- sub_geoms[0] = (char *)serialized_form;
- result->sub_geoms = (char **)sub_geoms;
+ sub_geoms = (uchar**) lwalloc(sizeof(char*));
+ sub_geoms[0] = (uchar *)serialized_form;
+ result->sub_geoms = (uchar **)sub_geoms;
return result;
}
if ( ! result->ngeometries ) return result;
- sub_geoms = (char**) lwalloc(sizeof(char*) * result->ngeometries );
+ sub_geoms = lwalloc(sizeof(uchar*) * result->ngeometries );
result->sub_geoms = sub_geoms;
- sub_geoms[0] = (char *)loc;
+ sub_geoms[0] = (uchar *)loc;
#ifdef PGIS_DEBUG
lwnotice("subgeom[0] @ %p (+%d)", sub_geoms[0], sub_geoms[0]-serialized_form);
#endif
// 1st geometry has geom_number = 0
// if the actual sub-geometry isnt a POINT, null is returned (see _gettype()).
// if there arent enough geometries, return null.
-// this is fine to call on a point (with geom_num=0), multipoint or geometrycollection
-LWPOINT *lwgeom_getpoint(char *serialized_form, int geom_number)
+// this is fine to call on a point (with geom_num=0),
+// multipoint or geometrycollection
+LWPOINT *
+lwgeom_getpoint(uchar *serialized_form, int geom_number)
{
- char type = lwgeom_getType((unsigned char)serialized_form[0]);
- char *sub_geom;
+ int type = lwgeom_getType((uchar)serialized_form[0]);
+ uchar *sub_geom;
if ((type == POINTTYPE) && (geom_number == 0))
{
if (sub_geom == NULL)
return NULL;
- type = lwgeom_getType( (unsigned char) sub_geom[0]);
+ type = lwgeom_getType(sub_geom[0]);
if (type != POINTTYPE)
return NULL;
LWPOINT *lwgeom_getpoint_inspected(LWGEOM_INSPECTED *inspected, int geom_number)
{
char *sub_geom;
- unsigned char type;
+ uchar type;
sub_geom = lwgeom_getsubgeometry_inspected(inspected, geom_number);
if (sub_geom == NULL) return NULL;
- type = lwgeom_getType( (unsigned char) sub_geom[0]);
+ type = lwgeom_getType( (uchar) sub_geom[0]);
if (type != POINTTYPE) return NULL;
return lwpoint_deserialize(sub_geom);
// if the actual geometry isnt a LINE, null is returned (see _gettype()).
// if there arent enough geometries, return null.
// this is fine to call on a line, multiline or geometrycollection
-LWLINE *lwgeom_getline(char *serialized_form, int geom_number)
+LWLINE *
+lwgeom_getline(uchar *serialized_form, int geom_number)
{
- unsigned char type = lwgeom_getType( (unsigned char) serialized_form[0]);
- char *sub_geom;
+ uchar type = lwgeom_getType( (uchar) serialized_form[0]);
+ uchar *sub_geom;
if ((type == LINETYPE) && (geom_number == 0))
{
sub_geom = lwgeom_getsubgeometry(serialized_form, geom_number);
if (sub_geom == NULL) return NULL;
- type = lwgeom_getType((unsigned char) sub_geom[0]);
+ type = lwgeom_getType((uchar) sub_geom[0]);
if (type != LINETYPE) return NULL;
return lwline_deserialize(sub_geom);
// this is fine to call on a line, multiline or geometrycollection
LWLINE *lwgeom_getline_inspected(LWGEOM_INSPECTED *inspected, int geom_number)
{
- char *sub_geom;
- unsigned char type;
+ uchar *sub_geom;
+ uchar type;
sub_geom = lwgeom_getsubgeometry_inspected(inspected, geom_number);
if (sub_geom == NULL) return NULL;
- type = lwgeom_getType((unsigned char) sub_geom[0]);
+ type = lwgeom_getType((uchar) sub_geom[0]);
if (type != LINETYPE) return NULL;
return lwline_deserialize(sub_geom);
// if the actual geometry isnt a POLYGON, null is returned (see _gettype()).
// if there arent enough geometries, return null.
// this is fine to call on a polygon, multipolygon or geometrycollection
-LWPOLY *lwgeom_getpoly(char *serialized_form, int geom_number)
+LWPOLY *
+lwgeom_getpoly(uchar *serialized_form, int geom_number)
{
- unsigned char type = lwgeom_getType((unsigned char)serialized_form[0]);
+ uchar type = lwgeom_getType((uchar)serialized_form[0]);
char *sub_geom;
if ((type == POLYGONTYPE) && (geom_number == 0))
sub_geom = lwgeom_getsubgeometry(serialized_form, geom_number);
if (sub_geom == NULL) return NULL;
- type = lwgeom_getType((unsigned char) sub_geom[0]);
+ type = lwgeom_getType((uchar) sub_geom[0]);
if (type != POLYGONTYPE) return NULL;
return lwpoly_deserialize(sub_geom);
LWPOLY *lwgeom_getpoly_inspected(LWGEOM_INSPECTED *inspected, int geom_number)
{
char *sub_geom;
- unsigned char type;
+ uchar type;
sub_geom = lwgeom_getsubgeometry_inspected(inspected, geom_number);
if (sub_geom == NULL) return NULL;
- type = lwgeom_getType((unsigned char) sub_geom[0]);
+ type = lwgeom_getType((uchar) sub_geom[0]);
if (type != POLYGONTYPE) return NULL;
return lwpoly_deserialize(sub_geom);
// ie. lwgeom_getpoint( lwgeom_getsubgeometry( serialized, 0), 1)
// --> POINT(1 1)
// you can inspect the sub-geometry as well if you wish.
-char *
-lwgeom_getsubgeometry(const char *serialized_form, int geom_number)
+uchar *
+lwgeom_getsubgeometry(const uchar *serialized_form, int geom_number)
{
//major cheat!!
char * result;
return result;
}
-char *
+uchar *
lwgeom_getsubgeometry_inspected(LWGEOM_INSPECTED *inspected, int geom_number)
{
if ((geom_number <0) || (geom_number >= inspected->ngeometries) )
// ie lwgeom_gettype( <'MULTIPOINT(0 0, 1 1)'>, 0)
// --> point
// gets the 8bit type of the geometry at location geom_number
-char
-lwgeom_getsubtype(char *serialized_form, int geom_number)
+uchar
+lwgeom_getsubtype(uchar *serialized_form, int geom_number)
{
//major cheat!!
char result;
return result;
}
-char lwgeom_getsubtype_inspected(LWGEOM_INSPECTED *inspected, int geom_number)
+uchar
+lwgeom_getsubtype_inspected(LWGEOM_INSPECTED *inspected, int geom_number)
{
if ((geom_number <0) || (geom_number >= inspected->ngeometries) )
return 99;
// how many sub-geometries are there?
// for point,line,polygon will return 1.
-int lwgeom_getnumgeometries(char *serialized_form)
+int
+lwgeom_getnumgeometries(uchar *serialized_form)
{
- unsigned char type = lwgeom_getType((unsigned char)serialized_form[0]);
- char *loc;
+ uchar type = lwgeom_getType((uchar)serialized_form[0]);
+ uchar *loc;
if ( (type==POINTTYPE) || (type==LINETYPE) || (type==POLYGONTYPE) )
{
loc = serialized_form+1;
- if (lwgeom_hasBBOX((unsigned char) serialized_form[0]))
+ if (lwgeom_hasBBOX((uchar) serialized_form[0]))
{
loc += sizeof(BOX2DFLOAT4);
}
- if (lwgeom_hasSRID((unsigned char) serialized_form[0]) )
+ if (lwgeom_hasSRID((uchar) serialized_form[0]) )
{
loc += 4;
}
// use SRID=-1 for unknown SRID (will have 8bit type's S = 0)
// all subgeometries must have the same SRID
// if you want to construct an inspected, call this then inspect the result...
-char *
-lwgeom_serialized_construct(int SRID, int finalType, char hasz, char hasm, int nsubgeometries, char **serialized_subs)
+uchar *
+lwgeom_serialized_construct(int SRID, int finalType, char hasz, char hasm, int nsubgeometries, uchar **serialized_subs)
{
uint32 *lengths;
int t;
int total_length = 0;
char type = -1;
char this_type = -1;
- char *result;
- char *loc;
+ uchar *result;
+ uchar *loc;
if (nsubgeometries == 0)
return lwgeom_constructempty(SRID, hasz, hasm);
{
lengths[t] = lwgeom_size_subgeom(serialized_subs[t],-1);
total_length += lengths[t];
- this_type = lwgeom_getType((unsigned char) (serialized_subs[t][0]));
+ this_type = lwgeom_getType((uchar) (serialized_subs[t][0]));
if (type == -1)
{
type = this_type;
total_length +=4 ; // nsubgeometries
result = lwalloc(total_length);
- result[0] = (unsigned char) lwgeom_makeType(hasz, hasm, SRID != -1, type);
+ result[0] = (uchar) lwgeom_makeType(hasz, hasm, SRID != -1, type);
if (SRID != -1)
{
memcpy(&result[1],&SRID,4);
// construct the empty geometry (GEOMETRYCOLLECTION(EMPTY))
//returns serialized form
-char *
+uchar *
lwgeom_constructempty(int SRID, char hasz, char hasm)
{
int size = 0;
- char *result;
+ uchar *result;
int ngeoms = 0;
- char *loc;
+ uchar *loc;
if (SRID != -1)
size +=4;
// writing it into the provided buffer.
void
lwgeom_constructempty_buf(int SRID, char hasz, char hasm,
- char *buf, size_t *retsize)
+ uchar *buf, size_t *retsize)
{
int ngeoms = 0;
- buf[0] =(unsigned char) lwgeom_makeType( hasz, hasm, SRID != -1, COLLECTIONTYPE);
+ buf[0] =(uchar) lwgeom_makeType( hasz, hasm, SRID != -1, COLLECTIONTYPE);
if (SRID != -1)
{
memcpy(&buf[1],&SRID,4);
// take a geometry, and find its length
size_t
-lwgeom_size(const char *serialized_form)
+lwgeom_size(const uchar *serialized_form)
{
- unsigned char type = lwgeom_getType((unsigned char) serialized_form[0]);
+ uchar type = lwgeom_getType((uchar) serialized_form[0]);
int t;
- const char *loc;
+ const uchar *loc;
uint32 ngeoms;
int sub_size;
int result = 1; //"type"
loc = serialized_form+1;
- if (lwgeom_hasBBOX((unsigned char) serialized_form[0]))
+ if (lwgeom_hasBBOX((uchar) serialized_form[0]))
{
#ifdef PGIS_DEBUG
lwnotice("lwgeom_size: has bbox");
result +=sizeof(BOX2DFLOAT4);
}
- if (lwgeom_hasSRID( (unsigned char) serialized_form[0]) )
+ if (lwgeom_hasSRID( (uchar) serialized_form[0]) )
{
#ifdef PGIS_DEBUG
lwnotice("lwgeom_size: has srid");
}
size_t
-lwgeom_size_subgeom(const char *serialized_form, int geom_number)
+lwgeom_size_subgeom(const uchar *serialized_form, int geom_number)
{
if (geom_number == -1)
{
//get bounding box of LWGEOM (automatically calls the sub-geometries bbox generators)
//dont forget to lwfree() result
BOX3D *
-lw_geom_getBB(char *serialized_form)
+lw_geom_getBB(uchar *serialized_form)
{
LWGEOM_INSPECTED *inspected = lwgeom_inspect(serialized_form);
// the given location, the function returns 0 is the geometry
// does not have a bounding box (EMPTY GEOM)
int
-compute_serialized_bbox_p(char *serialized_form, BOX2DFLOAT4 *out)
+compute_serialized_bbox_p(uchar *srl, BOX2DFLOAT4 *out)
{
- LWGEOM_INSPECTED *inspected = lwgeom_inspect(serialized_form);
+ LWGEOM_INSPECTED *inspected = lwgeom_inspect(srl);
BOX3D *result = lw_geom_getBB_inspected(inspected);
if ( ! result ) return 0;
}
//dont forget to lwfree() result
-BOX3D *lw_geom_getBB_simple(char *serialized_form)
+BOX3D *lw_geom_getBB_simple(uchar *serialized_form)
{
- int type = lwgeom_getType((unsigned char) serialized_form[0]);
+ int type = lwgeom_getType((uchar) serialized_form[0]);
int t;
- char *loc;
+ uchar *loc;
uint32 ngeoms;
BOX3D *result;
BOX3D *b1,*b2;
/*
result = lwalloc(sizeof(BOX3D));
memcpy(result, serialized_form+1, sizeof(BOX2DFLOAT4));
- memcpy(( (char *)result)+24, serialized_form+1, sizeof(BOX2DFLOAT4));
+ memcpy(((uchar *)result)+24, serialized_form+1, sizeof(BOX2DFLOAT4));
return result;
*/
}
loc = serialized_form+1;
- if (lwgeom_hasBBOX((unsigned char) serialized_form[0]))
+ if (lwgeom_hasBBOX((uchar) serialized_form[0]))
{
loc += sizeof(BOX2DFLOAT4);
}
- if (lwgeom_hasSRID((unsigned char) serialized_form[0]) )
+ if (lwgeom_hasSRID((uchar) serialized_form[0]) )
{
loc +=4;
}
{
int t;
POINT4D *pt;
- char *mflag;
+ uchar *mflag;
if ( TYPE_HASM(pa->dims) ) mflag = "M";
else mflag = "";
lwnotice(" }");
}
-void printBYTES(unsigned char *a, int n)
+void printBYTES(uchar *a, int n)
{
int t;
char buff[3];
void
-printMULTI(char *serialized)
+printMULTI(uchar *serialized)
{
LWGEOM_INSPECTED *inspected = lwgeom_inspect(serialized);
LWLINE *line;
LWPOLY *poly;
int t;
- lwnotice("MULTI* geometry (type = %i), with %i sub-geoms",lwgeom_getType((unsigned char)serialized[0]), inspected->ngeometries);
+ lwnotice("MULTI* geometry (type = %i), with %i sub-geoms",lwgeom_getType((uchar)serialized[0]), inspected->ngeometries);
for (t=0;t<inspected->ngeometries;t++)
{
pfree_inspected(inspected);
}
-void printType(unsigned char type)
+void printType(uchar type)
{
lwnotice("type 0x%x ==> hasBBOX=%i, hasSRID=%i, ndims=%i, type=%i",(unsigned int) type, lwgeom_hasBBOX(type), lwgeom_hasSRID(type),lwgeom_ndims(type), lwgeom_getType(type));
}
// get the SRID from the LWGEOM
// none present => -1
-int lwgeom_getsrid(char *serialized)
+int
+lwgeom_getsrid(uchar *serialized)
{
- unsigned char type = serialized[0];
- char *loc = serialized+1;
+ uchar type = serialized[0];
+ uchar *loc = serialized+1;
if ( ! lwgeom_hasSRID(type)) return -1;
// none present => -1
int pglwgeom_getSRID(PG_LWGEOM *lwgeom)
{
- unsigned char type = lwgeom->type;
- char *loc = lwgeom->data;
+ uchar type = lwgeom->type;
+ uchar *loc = lwgeom->data;
if ( ! lwgeom_hasSRID(type)) return -1;
PG_LWGEOM *
pglwgeom_setSRID(PG_LWGEOM *lwgeom, int32 newSRID)
{
- unsigned char type = lwgeom->type;
+ uchar type = lwgeom->type;
int bbox_offset=0; //0=no bbox, otherwise sizeof(BOX2DFLOAT4)
int len,len_new,len_left;
PG_LWGEOM *result;
- char *loc_new, *loc_old;
+ uchar *loc_new, *loc_old;
if (lwgeom_hasBBOX(type))
bbox_offset = sizeof(BOX2DFLOAT4);
}
PG_LWGEOM *
-PG_LWGEOM_construct(char *ser, int SRID, int wantbbox)
+PG_LWGEOM_construct(uchar *ser, int SRID, int wantbbox)
{
int size;
- char *iptr, *optr, *eptr;
+ uchar *iptr, *optr, *eptr;
int wantsrid = 0;
BOX2DFLOAT4 box;
PG_LWGEOM *result;
* and returns a list of _all_ subgeoms in it (deep-first)
*/
LWGEOM_EXPLODED *
-lwgeom_explode(char *serialized)
+lwgeom_explode(uchar *serialized)
{
LWGEOM_INSPECTED *inspected;
LWGEOM_EXPLODED *subexploded, *result;
for (i=0; i<inspected->ngeometries; i++)
{
- char *subgeom = inspected->sub_geoms[i];
+ uchar *subgeom = inspected->sub_geoms[i];
int type = lwgeom_getType(subgeom[0]);
if ( type == POINTTYPE )
lwnotice("lwgeom_explode: it's a point");
#endif
result->points = lwrealloc(result->points,
- (result->npoints+1)*sizeof(char *));
+ (result->npoints+1)*sizeof(uchar *));
result->points[result->npoints] = subgeom;
result->npoints++;
continue;
lwnotice("lwgeom_explode: it's a line");
#endif
result->lines = lwrealloc(result->lines,
- (result->nlines+1)*sizeof(char *));
+ (result->nlines+1)*sizeof(uchar *));
result->lines[result->nlines] = subgeom;
result->nlines++;
continue;
lwnotice("lwgeom_explode: it's a polygon");
#endif
result->polys = lwrealloc(result->polys,
- (result->npolys+1)*sizeof(char *));
+ (result->npolys+1)*sizeof(uchar *));
result->polys[result->npolys] = subgeom;
result->npolys++;
continue;
if ( subexploded->npoints )
{
result->points = lwrealloc(result->points,
- sizeof(char *)*(result->npoints+subexploded->npoints-1));
+ sizeof(uchar *)*(result->npoints+subexploded->npoints-1));
if ( ! result )
lwerror("Out of virtual memory");
memcpy(&(result->points[result->npoints]),
subexploded->points,
- subexploded->npoints*sizeof(char *));
+ subexploded->npoints*sizeof(uchar *));
#ifdef PGIS_DEBUG
lwnotice("memcpied exploded->points");
if ( subexploded->nlines )
{
result->lines = lwrealloc(result->lines,
- sizeof(char *)*
+ sizeof(uchar *)*
(result->nlines+subexploded->nlines-1));
memcpy(&(result->lines[result->nlines]),
subexploded->lines,
- subexploded->nlines*sizeof(char *));
+ subexploded->nlines*sizeof(uchar *));
result->nlines += subexploded->nlines;
}
if ( subexploded->npolys )
{
result->polys = lwrealloc(result->polys,
- sizeof(char *)*
+ sizeof(uchar *)*
(result->npolys+subexploded->npolys-1));
memcpy(&(result->polys[result->npolys]),
subexploded->polys,
- subexploded->npolys*sizeof(char *));
+ subexploded->npolys*sizeof(uchar *));
result->npolys += subexploded->npolys;
}
lwexploded_sum(LWGEOM_EXPLODED *exp1, LWGEOM_EXPLODED *exp2)
{
LWGEOM_EXPLODED *expcoll;
- char *loc;
+ uchar *loc;
if ( TYPE_GETZM(exp1->dims) != TYPE_GETZM(exp2->dims) )
{
expcoll->npoints = exp1->npoints + exp2->npoints;
if ( expcoll->npoints ) {
- expcoll->points = (char **)lwalloc(expcoll->npoints*sizeof(char *));
+ expcoll->points = lwalloc(expcoll->npoints*sizeof(char *));
loc = (char *)&(expcoll->points[0]);
if ( exp1->npoints ) {
memcpy(loc, exp1->points,
/*
* Serialized a LWGEOM_EXPLODED structure
*/
-char *
+uchar *
lwexploded_serialize(LWGEOM_EXPLODED *exploded, int wantbbox)
{
size_t sizecom = 0;
size_t size;
- char *result;
+ uchar *result;
size = lwexploded_findlength(exploded, wantbbox);
result = lwalloc(size);
*/
void
lwexploded_serialize_buf(LWGEOM_EXPLODED *exploded, int wantbbox,
- char *buf, size_t *retsize)
+ uchar *buf, size_t *retsize)
{
size_t size=0;
int i;
int ntypes = 0;
int ngeoms = 0;
- char *loc;
+ uchar *loc;
int outtype = 0;
LWPOLY *poly;
LWLINE *line;
#ifdef PGIS_DEBUG_EXPLODED
void
-checkexplodedsize(char *srl, LWGEOM_EXPLODED *exp, int alloced, char wantbbox)
+checkexplodedsize(uchar *srl, LWGEOM_EXPLODED *exp, int alloced, char wantbbox)
{
lwnotice("exploded len: serialized:%d computed:%d alloced:%d",
lwgeom_size(srl), lwexploded_findlength(exp, wantbbox),
return 1;
}
-const char *
-lwgeom_typeflags(unsigned char type)
+const uchar *
+lwgeom_typeflags(uchar type)
{
static char flags[5];
int flagno=0;
//given a string with at least 2 chars in it, convert them to
// a byte value. No error checking done!
-unsigned char
+uchar
parse_hex(char *str)
{
//do this a little brute force to make it faster
- unsigned char result_high = 0;
- unsigned char result_low = 0;
+ uchar result_high = 0;
+ uchar result_low = 0;
switch (str[0])
{
result_low = 15;
break;
}
- return (unsigned char) ((result_high<<4) + result_low);
+ return (uchar) ((result_high<<4) + result_low);
}
// -> mystr[0] = 'F' and mystr[1] = 'F'
// no error checking done
void
-deparse_hex(unsigned char str, unsigned char *result)
+deparse_hex(uchar str, uchar *result)
{
int input_high;
int input_low;
}
}
-char *
+uchar *
parse_lwgeom_wkt(char *wkt_input)
{
- char *serialized_form = parse_lwg((const char *)wkt_input,
+ uchar *serialized_form = parse_lwg(wkt_input,
lwalloc, lwerror);
#include "liblwgeom.h"
// External functions (what's again the reason for using explicit hex form ?)
-extern void deparse_hex(unsigned char str, unsigned char *result);
-extern unsigned char parse_hex(char *str);
+extern void deparse_hex(uchar str, uchar *result);
+extern uchar parse_hex(char *str);
// Internal funcs
void swap_char(char *a,char *b);
for (t=0;t<size;t++)
{
- ((unsigned char *)result)[t] = parse_hex( &str[t*2]) ;
+ ((uchar *)result)[t] = parse_hex( &str[t*2]) ;
}
// if endian is wrong, flip it otherwise do nothing
result->size = size;
for (t=0; t< (chip->size); t++)
{
- deparse_hex( ((unsigned char *) chip)[t], &result[t*2]);
+ deparse_hex( ((uchar *) chip)[t], &result[t*2]);
}
PG_RETURN_CSTRING(result);
}
int t;
- while (isspace((unsigned char) *str))
+ while (isspace(*str))
str++;
if (strstr(str,"HISTOGRAM2D(") != str)
/**********************************************************************
* $Log$
+ * Revision 1.23 2005/02/10 10:52:53 strk
+ * Changed 'char' to 'uchar' (unsigned char typedef) wherever octet is actually
+ * meant to be.
+ *
* Revision 1.22 2005/01/13 18:26:49 strk
* estimated_extent() implemented for PG<80
*
}
void
-lwgeom_translate_recursive(char *serialized,
+lwgeom_translate_recursive(uchar *serialized,
double xoff, double yoff, double zoff)
{
LWGEOM_INSPECTED *inspected;
LWLINE *line=NULL;
LWPOINT *point=NULL;
LWPOLY *poly=NULL;
- char *subgeom=NULL;
+ uchar *subgeom=NULL;
point = lwgeom_getpoint_inspected(inspected, i);
if (point !=NULL)
* Recursively count points in a SERIALIZED lwgeom
*/
int32
-lwgeom_npoints(char *serialized)
+lwgeom_npoints(uchar *serialized)
{
LWGEOM_INSPECTED *inspected = lwgeom_inspect(serialized);
int i, j;
LWLINE *line=NULL;
LWPOINT *point=NULL;
LWPOLY *poly=NULL;
- char *subgeom=NULL;
+ uchar *subgeom=NULL;
point = lwgeom_getpoint_inspected(inspected, i);
if (point !=NULL)
* Recursively count rings in a SERIALIZED lwgeom
*/
int32
-lwgeom_nrings_recursive(char *serialized)
+lwgeom_nrings_recursive(uchar *serialized)
{
LWGEOM_INSPECTED *inspected;
int i;
for (i=0; i<inspected->ngeometries; i++)
{
LWPOLY *poly=NULL;
- char *subgeom=NULL;
+ uchar *subgeom=NULL;
subgeom = lwgeom_getsubgeometry_inspected(inspected, i);
* Return number bytes written in given int pointer.
*/
void
-lwgeom_force2d_recursive(char *serialized, char *optr, size_t *retsize)
+lwgeom_force2d_recursive(uchar *serialized, uchar *optr, size_t *retsize)
{
LWGEOM_INSPECTED *inspected;
int i;
LWPOINT *point = NULL;
LWLINE *line = NULL;
LWPOLY *poly = NULL;
- char *loc;
+ uchar *loc;
#ifdef PGIS_DEBUG
inspected = lwgeom_inspect(serialized);
for (i=0; i<inspected->ngeometries; i++)
{
- char *subgeom = lwgeom_getsubgeometry_inspected(inspected, i);
+ uchar *subgeom = lwgeom_getsubgeometry_inspected(inspected, i);
lwgeom_force2d_recursive(subgeom, optr, &size);
totsize += size;
optr += size;
* Return number bytes written in given int pointer.
*/
void
-lwgeom_force3dz_recursive(char *serialized, char *optr, size_t *retsize)
+lwgeom_force3dz_recursive(uchar *serialized, uchar *optr, size_t *retsize)
{
LWGEOM_INSPECTED *inspected;
int i,j,k;
LWPOLY *poly = NULL;
POINTARRAY newpts;
POINTARRAY **nrings;
- char *loc;
+ uchar *loc;
#ifdef PGIS_DEBUG
inspected = lwgeom_inspect(serialized);
for (i=0; i<inspected->ngeometries; i++)
{
- char *subgeom = lwgeom_getsubgeometry_inspected(inspected, i);
+ uchar *subgeom = lwgeom_getsubgeometry_inspected(inspected, i);
lwgeom_force3dz_recursive(subgeom, optr, &size);
totsize += size;
optr += size;
* Return number bytes written in given int pointer.
*/
void
-lwgeom_force3dm_recursive(unsigned char *serialized, char *optr, size_t *retsize)
+lwgeom_force3dm_recursive(uchar *serialized, uchar *optr, size_t *retsize)
{
LWGEOM_INSPECTED *inspected;
int i,j,k;
size_t totsize=0;
size_t size=0;
int type;
- unsigned char newtypefl;
+ uchar newtypefl;
LWPOINT *point = NULL;
LWLINE *line = NULL;
LWPOLY *poly = NULL;
POINTARRAY newpts;
POINTARRAY **nrings;
POINT3DM *p3dm;
- char *loc;
+ uchar *loc;
char check;
inspected = lwgeom_inspect(serialized);
for (i=0; i<inspected->ngeometries; i++)
{
- char *subgeom = lwgeom_getsubgeometry_inspected(inspected, i);
+ uchar *subgeom = lwgeom_getsubgeometry_inspected(inspected, i);
lwgeom_force3dm_recursive(subgeom, optr, &size);
totsize += size;
optr += size;
* Return number bytes written in given int pointer.
*/
void
-lwgeom_force4d_recursive(char *serialized, char *optr, size_t *retsize)
+lwgeom_force4d_recursive(uchar *serialized, uchar *optr, size_t *retsize)
{
LWGEOM_INSPECTED *inspected;
int i,j,k;
LWPOLY *poly = NULL;
POINTARRAY newpts;
POINTARRAY **nrings;
- char *loc;
+ uchar *loc;
#ifdef PGIS_DEBUG
inspected = lwgeom_inspect(serialized);
for (i=0; i<inspected->ngeometries; i++)
{
- char *subgeom = lwgeom_getsubgeometry_inspected(inspected, i);
+ uchar *subgeom = lwgeom_getsubgeometry_inspected(inspected, i);
lwgeom_force4d_recursive(subgeom, optr, &size);
totsize += size;
optr += size;
Datum LWGEOM_force_2d(PG_FUNCTION_ARGS)
{
PG_LWGEOM *geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
- char *srl;
+ uchar *srl;
PG_LWGEOM *result;
size_t size = 0;
if ( lwgeom_ndims(geom->type) == 2 ) PG_RETURN_POINTER(geom);
// allocate a larger for safety and simplicity
- srl = (char *) lwalloc(geom->size);
+ srl = lwalloc(geom->size);
lwgeom_force2d_recursive(SERIALIZED_FORM(geom),
srl, &size);
Datum LWGEOM_force_3dz(PG_FUNCTION_ARGS)
{
PG_LWGEOM *geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
- char *srl;
+ uchar *srl;
PG_LWGEOM *result;
int olddims;
size_t size = 0;
if ( olddims == 3 && TYPE_HASZ(geom->type) ) PG_RETURN_POINTER(geom);
if ( olddims > 3 ) {
- srl = (char *) lwalloc(geom->size);
+ srl = lwalloc(geom->size);
} else {
// allocate double as memory a larger for safety
- srl = (char *) lwalloc(geom->size*1.5);
+ srl = lwalloc(geom->size*1.5);
}
lwgeom_force3dz_recursive(SERIALIZED_FORM(geom),
Datum LWGEOM_force_3dm(PG_FUNCTION_ARGS)
{
PG_LWGEOM *geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
- char *srl;
+ uchar *srl;
PG_LWGEOM *result;
int olddims;
size_t size = 0;
// allocate double as memory a larger for safety
size = geom->size * 1.5;
}
- srl = (char *)lwalloc(size);
+ srl = lwalloc(size);
#ifdef PGIS_DEBUG
lwnotice("LWGEOM_force_3dm: allocated %d bytes for result", size);
Datum LWGEOM_force_4d(PG_FUNCTION_ARGS)
{
PG_LWGEOM *geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
- char *srl;
+ uchar *srl;
PG_LWGEOM *result;
int olddims;
size_t size = 0;
if ( olddims == 4 ) PG_RETURN_POINTER(geom);
// allocate double as memory a larger for safety
- srl = (char *)lwalloc(geom->size*2);
+ srl = lwalloc(geom->size*2);
lwgeom_force4d_recursive(SERIALIZED_FORM(geom),
srl, &size);
Datum LWGEOM_translate(PG_FUNCTION_ARGS)
{
PG_LWGEOM *geom = (PG_LWGEOM *)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
- char *srl = SERIALIZED_FORM(geom);
+ uchar *srl = SERIALIZED_FORM(geom);
BOX2DFLOAT4 *box;
double xoff = PG_GETARG_FLOAT8(1);
elog(NOTICE, "geom_accum: adding %p (nelems=%d; nbytes=%d)",
geom, nelems, nbytes);
#endif
- result = (ArrayType *) lwalloc(nbytes);
+ result = lwalloc(nbytes);
if ( ! result )
{
elog(ERROR, "Out of virtual memory");
#ifdef PGIS_DEBUG
elog(NOTICE, " array start @ %p", result);
elog(NOTICE, " ARR_DATA_PTR @ %p (%d)",
- ARR_DATA_PTR(result), (char *)ARR_DATA_PTR(result)-(char *)result);
- elog(NOTICE, " next element @ %p", (char *)result+oldsize);
+ ARR_DATA_PTR(result), (uchar *)ARR_DATA_PTR(result)-(uchar *)result);
+ elog(NOTICE, " next element @ %p", (uchar *)result+oldsize);
#endif
result->size = nbytes;
memcpy(ARR_DIMS(result), &nelems, sizeof(int));
elog(NOTICE, " writing next element starting @ %p",
result+oldsize);
#endif
- memcpy((char *)result+oldsize, geom, geom->size);
+ memcpy((uchar *)result+oldsize, geom, geom->size);
}
#ifdef PGIS_DEBUG
// Construct point array
pa[0] = lwalloc(sizeof(POINTARRAY));
- pa[0]->serialized_pointlist = (char *)pts;
+ pa[0]->serialized_pointlist = (uchar *)pts;
TYPE_SETZM(pa[0]->dims, 0, 0);
pa[0]->npoints = 5;
LWPOLY *poly;
int SRID;
PG_LWGEOM *result;
- char *ser;
+ uchar *ser;
// get bounding box
if ( ! getbox2d_p(SERIALIZED_FORM(geom), &box) )
// Construct point array
pa[0] = lwalloc(sizeof(POINTARRAY));
- pa[0]->serialized_pointlist = (char *)pts;
+ pa[0]->serialized_pointlist = (uchar *)pts;
TYPE_SETZM(pa[0]->dims, 0, 0);
pa[0]->npoints = 5;
POINT3DZ *p, cent;
int i,j,k;
uint32 num_points_tot = 0;
- char *srl;
+ uchar *srl;
char wantbbox = 0;
double tot_x=0, tot_y=0, tot_z=0;
cent.z = tot_z/num_points_tot;
// Construct POINTARRAY (paranoia?)
- pa = pointArray_construct((char *)¢, 1, 0, 1);
+ pa = pointArray_construct((uchar *)¢, 1, 0, 1);
// Construct LWPOINT
point = lwpoint_construct(SRID, NULL, pa);
Datum LWGEOM_zmflag(PG_FUNCTION_ARGS)
{
PG_LWGEOM *in;
- unsigned char type;
+ uchar type;
int ret = 0;
in = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
// WKB structure -- exactly the same as TEXT
typedef struct Well_known_bin {
int32 size; // total size of this structure
- unsigned char data[1]; //THIS HOLD VARIABLE LENGTH DATA
+ uchar data[1]; //THIS HOLD VARIABLE LENGTH DATA
} WellKnownBinary;
for (t=0; t< (wkb_input->size -VARHDRSZ); t++)
{
- deparse_hex( ((unsigned char *) wkb_input)[4 + t], &loc[t*2]);
+ deparse_hex( ((uchar *) wkb_input)[4 + t], &loc[t*2]);
}
wkb_srid_hexized[size_result-1] = 0; // null term
// have a hexized string, want to make it binary
for (t=0; t< (size/2); t++)
{
- ((unsigned char *) result +VARHDRSZ)[t] = parse_hex( hexized_wkb + (t*2) );
+ ((uchar *) result +VARHDRSZ)[t] = parse_hex( hexized_wkb + (t*2) );
}
pfree(hexized_wkb_srid);
PG_LWGEOM *lwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
PG_LWGEOM *result;
BOX2DFLOAT4 box;
- unsigned char old_type;
+ uchar old_type;
int size;
//elog(NOTICE,"in LWGEOM_addBBOX");
}
char
-is_worth_caching_serialized_bbox(const char *in)
+is_worth_caching_serialized_bbox(const uchar *in)
{
#if ! AUTOCACHE_BBOX
return false;
#endif
- if ( TYPE_GETTYPE((unsigned char)in[0]) == POINTTYPE ) return false;
+ if ( TYPE_GETTYPE((uchar)in[0]) == POINTTYPE ) return false;
return true;
}
{
PG_LWGEOM *lwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
PG_LWGEOM *result;
- unsigned char old_type;
- int size;
+ uchar old_type;
+ int size;
//elog(NOTICE,"in LWGEOM_dropBBOX");
char *text_ob;
char *result;
int32 size;
- unsigned char type;
+ uchar type;
init_pg_func();
// serialized_form should point to the 8bit type format (with type = 2)
// See serialized form doc
LWLINE *
-lwline_deserialize(char *serialized_form)
+lwline_deserialize(uchar *serialized_form)
{
- unsigned char type;
+ uchar type;
LWLINE *result;
- char *loc =NULL;
+ uchar *loc =NULL;
uint32 npoints;
POINTARRAY *pa;
- type = (unsigned char) serialized_form[0];
+ type = (uchar) serialized_form[0];
if ( lwgeom_getType(type) != LINETYPE)
{
// convert this line into its serialize form
// result's first char will be the 8bit type. See serialized form doc
-char *
+uchar *
lwline_serialize(LWLINE *line)
{
size_t size, retsize;
- char * result;
+ uchar * result;
if (line == NULL) lwerror("lwline_serialize:: given null line");
// the given int pointer.
// result's first char will be the 8bit type. See serialized form doc
void
-lwline_serialize_buf(LWLINE *line, char *buf, size_t *retsize)
+lwline_serialize_buf(LWLINE *line, uchar *buf, size_t *retsize)
{
char hasSRID;
- char *loc;
+ uchar *loc;
int ptsize = pointArray_ptsize(line->points);
unsigned int u;
hasSRID = (line->SRID != -1);
- buf[0] = (unsigned char) lwgeom_makeType_full(
+ buf[0] = (uchar) lwgeom_makeType_full(
TYPE_HASZ(line->type), TYPE_HASM(line->type),
hasSRID, LINETYPE, line->bbox ? 1 : 0);
loc = buf+1;
if (retsize) *retsize = loc-buf;
- //printBYTES((unsigned char *)result, loc-buf);
+ //printBYTES((uchar *)result, loc-buf);
#ifdef PGIS_DEBUG_CALLS
lwnotice("lwline_serialize_buf returning (loc: %p, size: %d)",
// find length of this serialized line
size_t
-lwgeom_size_line(const char *serialized_line)
+lwgeom_size_line(const uchar *serialized_line)
{
- int type = (unsigned char) serialized_line[0];
+ int type = (uchar) serialized_line[0];
uint32 result = 1; //type
- const char *loc;
+ const uchar *loc;
uint32 npoints;
#ifdef PGIS_DEBUG_CALLS
#include "liblwgeom.h"
LWMLINE *
-lwmline_deserialize(char *srl)
+lwmline_deserialize(uchar *srl)
{
LWMLINE *result;
LWGEOM_INSPECTED *insp;
#include "liblwgeom.h"
LWMPOINT *
-lwmpoint_deserialize(char *srl)
+lwmpoint_deserialize(uchar *srl)
{
LWMPOINT *result;
LWGEOM_INSPECTED *insp;
//#define PGIS_DEBUG_CALLS 1
LWMPOLY *
-lwmpoly_deserialize(char *srl)
+lwmpoly_deserialize(uchar *srl)
{
LWMPOLY *result;
LWGEOM_INSPECTED *insp;
// convert this point into its serialize form
// result's first char will be the 8bit type. See serialized form doc
-char *
+uchar *
lwpoint_serialize(LWPOINT *point)
{
size_t size, retsize;
- char *result;
+ uchar *result;
size = lwpoint_serialize_size(point);
result = lwalloc(size);
// the given int pointer.
// result's first char will be the 8bit type. See serialized form doc
void
-lwpoint_serialize_buf(LWPOINT *point, char *buf, size_t *retsize)
+lwpoint_serialize_buf(LWPOINT *point, uchar *buf, size_t *retsize)
{
int size=1;
char hasSRID;
- char *loc;
+ uchar *loc;
//printLWPOINT(point);
#ifdef PGIS_DEBUG_CALLS
size += sizeof(double)*TYPE_NDIMS(point->type);
- buf[0] = (unsigned char) lwgeom_makeType_full(
+ buf[0] = (uchar) lwgeom_makeType_full(
TYPE_HASZ(point->type), TYPE_HASM(point->type),
hasSRID, POINTTYPE, point->bbox?1:0);
loc = buf+1;
// serialized_form should point to the 8bit type format (with type = 1)
// See serialized form doc
LWPOINT *
-lwpoint_deserialize(char *serialized_form)
+lwpoint_deserialize(uchar *serialized_form)
{
- unsigned char type;
+ uchar type;
LWPOINT *result;
- char *loc = NULL;
+ uchar *loc = NULL;
POINTARRAY *pa;
#ifdef PGIS_DEBUG_CALLS
result = (LWPOINT*) lwalloc(sizeof(LWPOINT)) ;
- type = (unsigned char) serialized_form[0];
+ type = (uchar) serialized_form[0];
if ( lwgeom_getType(type) != POINTTYPE) return NULL;
result->type = type;
//find length of this serialized point
size_t
-lwgeom_size_point(const char *serialized_point)
+lwgeom_size_point(const uchar *serialized_point)
{
uint32 result = 1;
- unsigned char type;
- const char *loc;
+ uchar type;
+ const uchar *loc;
- type = (unsigned char) serialized_point[0];
+ type = serialized_point[0];
if ( lwgeom_getType(type) != POINTTYPE) return 0;
// serialized_form should point to the 8bit type format (with type = 3)
// See serialized form doc
LWPOLY *
-lwpoly_deserialize(char *serialized_form)
+lwpoly_deserialize(uchar *serialized_form)
{
LWPOLY *result;
uint32 nrings;
int ndims, hasz, hasm;
uint32 npoints;
- unsigned char type;
+ uchar type;
char *loc;
int t;
// create the serialized form of the polygon
// result's first char will be the 8bit type. See serialized form doc
// points copied
-char *
+uchar *
lwpoly_serialize(LWPOLY *poly)
{
size_t size, retsize;
- char *result;
+ uchar *result;
size = lwpoly_serialize_size(poly);
result = lwalloc(size);
// result's first char will be the 8bit type. See serialized form doc
// points copied
void
-lwpoly_serialize_buf(LWPOLY *poly, char *buf, size_t *retsize)
+lwpoly_serialize_buf(LWPOLY *poly, uchar *buf, size_t *retsize)
{
int size=1; // type byte
char hasSRID;
int t,u;
int total_points = 0;
int npoints;
- char *loc;
+ uchar *loc;
#ifdef PGIS_DEBUG_CALLS
lwnotice("lwpoly_serialize_buf called");
}
size += sizeof(double)*TYPE_NDIMS(poly->type)*total_points;
- buf[0] = (unsigned char) lwgeom_makeType_full(
+ buf[0] = (uchar) lwgeom_makeType_full(
TYPE_HASZ(poly->type), TYPE_HASM(poly->type),
hasSRID, POLYGONTYPE, poly->bbox ? 1 : 0);
loc = buf+1;
//find length of this serialized polygon
size_t
-lwgeom_size_poly(const char *serialized_poly)
+lwgeom_size_poly(const uchar *serialized_poly)
{
uint32 result = 1; // char type
uint32 nrings;
- int ndims;
+ int ndims;
int t;
- unsigned char type;
+ uchar type;
uint32 npoints;
- const char *loc;
+ const uchar *loc;
if (serialized_poly == NULL)
return -9999;
- type = (unsigned char) serialized_poly[0];
+ type = (uchar) serialized_poly[0];
ndims = lwgeom_ndims(type);
if ( lwgeom_getType(type) != POLYGONTYPE)
}
double
-lwgeom_mindistance2d_recursive(char *lw1, char *lw2)
+lwgeom_mindistance2d_recursive(uchar *lw1, uchar *lw2)
{
LWGEOM_INSPECTED *in1, *in2;
int i, j;
for (i=0; i<in1->ngeometries; i++)
{
- char *g1 = lwgeom_getsubgeometry_inspected(in1, i);
+ uchar *g1 = lwgeom_getsubgeometry_inspected(in1, i);
int t1 = lwgeom_getType(g1[0]);
double dist=0;
for (j=0; j<in2->ngeometries; j++)
{
- char *g2 = lwgeom_getsubgeometry_inspected(in2, j);
+ uchar *g2 = lwgeom_getsubgeometry_inspected(in2, j);
int t2 = lwgeom_getType(g2[0]);
if ( t1 == POINTTYPE )
POINTARRAY *
ptarray_construct(char hasz, char hasm, unsigned int npoints)
{
- unsigned char dims = 0;
+ uchar dims = 0;
size_t size;
- char *ptlist;
+ uchar *ptlist;
POINTARRAY *pa;
TYPE_SETZM(dims, hasz?1:0, hasm?1:0);
size = TYPE_NDIMS(dims)*npoints*sizeof(double);
- ptlist = (char *)lwalloc(size);
+
+ ptlist = (uchar *)lwalloc(size);
pa = lwalloc(sizeof(POINTARRAY));
pa->dims = dims;
pa->serialized_pointlist = ptlist;
for (i=0; i<=mid; i++)
{
- char *from, *to;
+ uchar *from, *to;
from = getPoint(pa, i);
to = getPoint(pa, (last-i));
- memcpy((char *)&pbuf, to, ptsize);
+ memcpy((uchar *)&pbuf, to, ptsize);
memcpy(to, from, ptsize);
- memcpy(from, (char *)&pbuf, ptsize);
+ memcpy(from, (uchar *)&pbuf, ptsize);
}
}
opa = (POINTARRAY *)lwalloc(ptsize * maxpoints);
opa->dims = ipa->dims;
opa->npoints = 0;
- opa->serialized_pointlist = (char *)lwalloc(maxpoints*ptsize);
+ opa->serialized_pointlist = (uchar *)lwalloc(maxpoints*ptsize);
// Add first point
opa->npoints++;
// Add point
if ( ++(opa->npoints) > maxpoints ) {
maxpoints *= 1.5;
- opa->serialized_pointlist = (char *)lwrealloc(
+ opa->serialized_pointlist = (uchar *)lwrealloc(
opa->serialized_pointlist,
maxpoints*ptsize
);
* if 'where' == -1 append is required.
*/
POINTARRAY *
-ptarray_addPoint(POINTARRAY *pa, char *p, size_t pdims, unsigned int where)
+ptarray_addPoint(POINTARRAY *pa, uchar *p, size_t pdims, unsigned int where)
{
POINTARRAY *ret;
POINT4D pbuf;
#endif
pbuf.x = pbuf.y = pbuf.z = pbuf.m = 0.0;
- memcpy((char *)&pbuf, p, pdims*sizeof(double));
+ memcpy((uchar *)&pbuf, p, pdims*sizeof(double));
#if PGIS_DEBUG
lwnotice("ptarray_addPoint: initialized point buffer");
memcpy(getPoint(ret, 0), getPoint(pa, 0), ptsize*where);
}
- memcpy(getPoint(ret, where), (char *)&pbuf, ptsize);
+ memcpy(getPoint(ret, where), (uchar *)&pbuf, ptsize);
if ( where+1 != ret->npoints )
{