]> granicus.if.org Git - postgis/commitdiff
Added simpler lwpoint constructors.
authorSandro Santilli <strk@keybit.net>
Wed, 13 Oct 2004 14:26:36 +0000 (14:26 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 13 Oct 2004 14:26:36 +0000 (14:26 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@989 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/liblwgeom.h
lwgeom/lwgeom.h
lwgeom/lwpoint.c
lwgeom/test.c

index 0a33ee1062cfc8887b999d5d9ecbd2c5b11e0870..01e887b79f05ffefe85725a91b99ff6d618923d0 100644 (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);
 
index 9c475a54798983e3c00c7f78893a26c038b00b67..55590be1d8317abf4a84a58f50bee43650d66790 100644 (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);
index 365716a794660759dfa275006a5fff88e408736f..36c02ab8763f5625d63d5ca771927d45a02340a4 100644 (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)
index 78cfc7e1846508a3ec7cc8291c4ab5fc5af1ad0e..4eabf3da5a702055cccd624d5282e57f53279560 100644 (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;
 }