]> granicus.if.org Git - postgis/commitdiff
Changed ptarray2d_construct interface.
authorSandro Santilli <strk@keybit.net>
Thu, 7 Oct 2004 17:18:50 +0000 (17:18 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 7 Oct 2004 17:18:50 +0000 (17:18 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@955 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/liblwgeom.h
lwgeom/lwgeom.h
lwgeom/ptarray.c
lwgeom/test.c

index 9b81dc455128b79775bb7e513c9ba498b078ea82..a9c10250686d3daceb628d29371bfab19f8d2de5 100644 (file)
@@ -953,7 +953,7 @@ extern const char *lwgeom_typeflags(unsigned char type);
 
 // Construct an empty pointarray
 extern POINTARRAY *ptarray_construct(char hasz, char hasm, unsigned int npoints);
-extern POINTARRAY *ptarray_construct2d(uint32 npoints, POINT2D const* const* pts);
+extern POINTARRAY *ptarray_construct2d(uint32 npoints, const POINT2D *pts);
 
 extern int32 lwgeom_nrings_recursive(char *serialized);
 extern void dump_lwexploded(LWGEOM_EXPLODED *exploded);
index 55f6fd2a59189c9d6bbbc83969ee9d4837c4ea04..084003a9b2808dc82557e60828b46f5e09679611 100644 (file)
@@ -21,7 +21,7 @@ typedef struct { double x; double y; double z; double m; } POINT4D;
 typedef struct POINTARRAY_T *POINTARRAY;
 
 // Constructs a POINTARRAY copying given 2d points
-POINTARRAY ptarray_construct2d(unsigned int npoints, POINT2D ** pts);
+POINTARRAY ptarray_construct2d(unsigned int npoints, const POINT2D *pts);
 
 /*****************************************************************
  * LWGEOM
@@ -34,6 +34,7 @@ extern char *lwgeom_to_wkt(LWGEOM lwgeom);
 
 // Construction
 extern LWGEOM lwpoint_construct(int SRID, char wantbbox, POINTARRAY pa);
+extern LWGEOM lwline_construct(int SRID, char wantbbox, POINTARRAY pa);
 
 // Spatial functions
 extern void lwgeom_reverse(LWGEOM lwgeom);
index 2d9eb5a31ac3ee075fa9bbeda883bb4677af748e..e02cc361423d31d4ca1d9a99d9eeeb0b6731f076 100644 (file)
@@ -12,7 +12,7 @@ ptarray_construct(char hasz, char hasm, unsigned int npoints)
        POINTARRAY *pa;
        
        TYPE_SETZM(dims, hasz?1:0, hasm?1:0);
-       size = TYPE_NDIMS(dims)*npoints;
+       size = TYPE_NDIMS(dims)*npoints*sizeof(double);
        ptlist = (char *)lwalloc(size);
        pa = lwalloc(sizeof(POINTARRAY));
        pa->dims = dims;
@@ -24,7 +24,7 @@ ptarray_construct(char hasz, char hasm, unsigned int npoints)
 }
 
 POINTARRAY *
-ptarray_construct2d(uint32 npoints, POINT2D const* const* pts)
+ptarray_construct2d(uint32 npoints, const POINT2D *pts)
 {
        POINTARRAY *pa = ptarray_construct(0, 0, npoints);
        uint32 i;
@@ -32,8 +32,8 @@ ptarray_construct2d(uint32 npoints, POINT2D const* const* pts)
        for (i=0; i<npoints; i++)
        {
                POINT2D *pap = (POINT2D *)getPoint(pa, i);
-               pap->x = pts[i]->x;
-               pap->y = pts[i]->y;
+               pap->x = pts[i].x;
+               pap->y = pts[i].y;
        }
        
        return pa;
index 2cf580c77a31d9ddd6aee918951f6c082736abe0..ddb951b0a9bb22e7a5e2781ad26fdf93c3c67f83 100644 (file)
@@ -3,20 +3,24 @@
 
 int main()
 {
-       POINT2D *pts2d[10];
-       POINT3DM *pts3dm[10];
-       POINT3DZ *pts3dz[10];
-       POINT4D *pts4d[10];
+       POINT2D pts2d[10];
        unsigned int npoints;
        POINTARRAY pa;
        LWGEOM point, line, poly;
 
        // Construct a point2d
-       pts2d[0] = lwalloc(sizeof(POINT2D));
-       pts2d[0]->x = 10;
-       pts2d[0]->y = 20;
+       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 pointarray2d
+       // Construct a single-point pointarray2d
        pa = ptarray_construct2d(1, pts2d);
 
        // Construct a point LWGEOM
@@ -25,5 +29,14 @@ int main()
        // Print WKT
        printf("WKT: %s\n", lwgeom_to_wkt(point));
 
+       // Construct a 5-points pointarray2d
+       pa = ptarray_construct2d(5, pts2d);
+
+       // Construct a line LWGEOM
+       line = lwline_construct(-1, 0, pa);
+
+       // Print WKT
+       printf("WKT: %s\n", lwgeom_to_wkt(line));
+
        return 1;
 }