Added simpler lwpoint constructors.

git-svn-id: http://svn.osgeo.org/postgis/trunk@989 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
Sandro Santilli 2004-10-13 14:26:36 +00:00
parent 01a17bd7cb
commit 53559edffe
4 changed files with 56 additions and 32 deletions

View file

@ -985,6 +985,12 @@ extern LWCOLLECTION *lwcollection_construct(unsigned int type, int SRID,
extern LWCOLLECTION *lwcollection_construct_empty(int SRID,
char hasZ, char hasM);
// Other constructors
extern LWPOINT *make_lwpoint2d(int SRID, double x, double y);
extern LWPOINT *make_lwpoint3dz(int SRID, double x, double y, double z);
extern LWPOINT *make_lwpoint3dm(int SRID, double x, double y, double m);
extern LWPOINT *make_lwpoint4d(int SRID, double x, double y, double z, double m);
// Return a char string with ASCII versionf of type flags
extern const char *lwgeom_typeflags(unsigned char type);

View file

@ -34,8 +34,10 @@ extern char *lwgeom_to_wkt(LWGEOM lwgeom);
extern char *lwgeom_to_hexwkb(LWGEOM lwgeom, unsigned int byteorder);
// Construction
extern LWGEOM lwpoint_construct(int SRID, char wantbbox, POINTARRAY pa);
extern LWGEOM lwline_construct(int SRID, char wantbbox, POINTARRAY pa);
extern LWGEOM make_lwpoint2d(int SRID, double x, double y);
extern LWGEOM make_lwpoint3dz(int SRID, double x, double y, double z);
extern LWGEOM make_lwpoint3dm(int SRID, double x, double y, double m);
extern LWGEOM make_lwpoint4d(int SRID, double x, double y, double z, double m);
// Spatial functions
extern void lwgeom_reverse(LWGEOM lwgeom);

View file

@ -170,6 +170,50 @@ lwpoint_construct(int SRID, BOX2DFLOAT4 *bbox, POINTARRAY *point)
return result;
}
LWPOINT *
make_lwpoint2d(int SRID, double x, double y)
{
POINTARRAY *pa = ptarray_construct(0, 0, 1);
POINT2D *p = (POINT2D *)getPoint(pa, 0);
p->x = x;
p->y = y;
return lwpoint_construct(SRID, NULL, pa);
}
LWPOINT *
make_lwpoint3dz(int SRID, double x, double y, double z)
{
POINTARRAY *pa = ptarray_construct(1, 0, 1);
POINT3DZ *p = (POINT3DZ *)getPoint(pa, 0);
p->x = x;
p->y = y;
p->z = z;
return lwpoint_construct(SRID, NULL, pa);
}
LWPOINT *
make_lwpoint3dm(int SRID, double x, double y, double m)
{
POINTARRAY *pa = ptarray_construct(0, 1, 1);
POINT3DM *p = (POINT3DM *)getPoint(pa, 0);
p->x = x;
p->y = y;
p->m = m;
return lwpoint_construct(SRID, NULL, pa);
}
LWPOINT *
make_lwpoint4d(int SRID, double x, double y, double z, double m)
{
POINTARRAY *pa = ptarray_construct(1, 1, 1);
POINT4D *p = (POINT4D *)getPoint(pa, 0);
p->x = x;
p->y = y;
p->z = z;
p->m = m;
return lwpoint_construct(SRID, NULL, pa);
}
// given the LWPOINT serialized form (or a pointer into a muli* one)
// construct a proper LWPOINT.
// serialized_form should point to the 8bit type format (with type = 1)

View file

@ -3,42 +3,14 @@
int main()
{
POINT2D pts2d[10];
unsigned int npoints;
POINTARRAY pa;
LWGEOM point, line, poly;
LWGEOM point;
// Construct a point2d
pts2d[0].x = 10;
pts2d[0].y = 10;
pts2d[1].x = 10;
pts2d[1].y = 20;
pts2d[2].x = 20;
pts2d[2].y = 20;
pts2d[3].x = 20;
pts2d[3].y = 10;
pts2d[4].x = 10;
pts2d[4].y = 10;
// Construct a single-point pointarray2d
pa = ptarray_construct2d(1, pts2d);
// Construct a point LWGEOM
point = lwpoint_construct(-1, 0, pa);
point = make_lwpoint2d(-1, 10, 20);
// Print WKT end HEXWKB
printf("WKT: %s\n", lwgeom_to_wkt(point));
printf("HEXWKB: %s\n", lwgeom_to_hexwkb(point,-1));
// Construct a 5-points pointarray2d
pa = ptarray_construct2d(5, pts2d);
// Construct a line LWGEOM
line = lwline_construct(-1, 0, pa);
// Print WKT and HEXWKB
printf("WKT: %s\n", lwgeom_to_wkt(line));
printf("HEXWKB: %s\n", lwgeom_to_hexwkb(point,-1));
return 1;
}