extern void lwgeom_scale(LWGEOM *geom, const POINT4D *factors);
extern int lwgeom_dimension(const LWGEOM *geom);
-extern LWPOINT* lwline_get_lwpoint(LWLINE *line, int where);
-extern LWPOINT* lwcircstring_get_lwpoint(LWCIRCSTRING *circ, int where);
+extern LWPOINT* lwline_get_lwpoint(const LWLINE *line, int where);
+extern LWPOINT* lwcircstring_get_lwpoint(const LWCIRCSTRING *circ, int where);
+
+extern LWPOINT* lwcompound_get_startpoint(const LWCOMPOUND *lwcmp);
+extern LWPOINT* lwcompound_get_endpoint(const LWCOMPOUND *lwcmp);
+extern LWPOINT* lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, int where);
+
extern double ptarray_length_2d(const POINTARRAY *pts);
extern double ptarray_length(const POINTARRAY *pts);
* Returns freshly allocated #LWPOINT that corresponds to the index where.
* Returns NULL if the geometry is empty or the index invalid.
*/
-LWPOINT* lwcircstring_get_lwpoint(LWCIRCSTRING *circ, int where) {
+LWPOINT* lwcircstring_get_lwpoint(const LWCIRCSTRING *circ, int where) {
POINT4D pt;
LWPOINT *lwpoint;
POINTARRAY *pa;
/* ogeom->bbox = lwline->bbox; */
return ogeom;
}
+
+LWPOINT*
+lwcompound_get_lwpoint(const LWCOMPOUND *lwcmp, int where)
+{
+ int i;
+ int count = 0;
+ int npoints = 0;
+ if ( lwgeom_is_empty((LWGEOM*)lwcmp) )
+ return NULL;
+
+ npoints = lwgeom_count_vertices((LWGEOM*)lwcmp);
+ if ( where < 0 || where >= npoints )
+ {
+ lwerror("%s: index %d is not in range of number of vertices (%d) in input", __func__, where, npoints);
+ return NULL;
+ }
+
+ for ( i = 0; i < lwcmp->ngeoms; i++ )
+ {
+ LWGEOM* part = lwcmp->geoms[i];
+ int npoints_part = lwgeom_count_vertices(part);
+ if ( where >= count && where < count + npoints_part )
+ {
+ return lwline_get_lwpoint((LWLINE*)part, where - count);
+ }
+ else
+ {
+ count += npoints_part;
+ }
+ }
+
+ return NULL;
+}
+
+
+
+LWPOINT *
+lwcompound_get_startpoint(const LWCOMPOUND *lwcmp)
+{
+ return lwcompound_get_lwpoint(lwcmp, 0);
+}
+
+LWPOINT *
+lwcompound_get_endpoint(const LWCOMPOUND *lwcmp)
+{
+ LWLINE *lwline;
+ if ( lwcmp->ngeoms < 1 )
+ {
+ return NULL;
+ }
+
+ lwline = (LWLINE*)(lwcmp->geoms[lwcmp->ngeoms-1]);
+
+ if ( (!lwline) || (!lwline->points) || (lwline->points->npoints < 1) )
+ {
+ return NULL;
+ }
+
+ return lwline_get_lwpoint(lwline, lwline->points->npoints-1);
+}
+
+
\ No newline at end of file
* Returns NULL if the geometry is empty or the index invalid.
*/
LWPOINT*
-lwline_get_lwpoint(LWLINE *line, int where)
+lwline_get_lwpoint(const LWLINE *line, int where)
{
POINT4D pt;
LWPOINT *lwpoint;
GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
int count = -1;
+ int type = lwgeom->type;
- if ( lwgeom->type == LINETYPE || lwgeom->type == CIRCSTRINGTYPE )
+ if ( type == LINETYPE || type == CIRCSTRINGTYPE || type == COMPOUNDTYPE )
count = lwgeom_count_vertices(lwgeom);
lwgeom_free(lwgeom);
/* OGC index starts at one, so we substract first. */
lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, where - 1);
}
+ else if ( type == COMPOUNDTYPE )
+ {
+ lwpoint = lwcompound_get_lwpoint((LWCOMPOUND*)lwgeom, where - 1);
+ }
lwgeom_free(lwgeom);
PG_FREE_IF_COPY(geom, 0);
{
lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, 0);
}
+ else if ( type == COMPOUNDTYPE )
+ {
+ lwpoint = lwcompound_get_startpoint((LWCOMPOUND*)lwgeom);
+ }
lwgeom_free(lwgeom);
PG_FREE_IF_COPY(geom, 0);
if ( line->points )
lwpoint = lwline_get_lwpoint((LWLINE*)lwgeom, line->points->npoints - 1);
}
+ else if ( type == COMPOUNDTYPE )
+ {
+ lwpoint = lwcompound_get_endpoint((LWCOMPOUND*)lwgeom);
+ }
lwgeom_free(lwgeom);
PG_FREE_IF_COPY(geom, 0);
SELECT 'valid wkb compound curve 3', ST_asEWKT(ST_GeomFromEWKB(decode('0109000000010000000102000000030000000CE586D73CF36240BBC46888F0523BC0102E91C951E76240DF90A1BEC0F841C0F970C100FFD7624074ADE6CE86CD3BC0', 'hex')));
SELECT 'valid wkb compound curve 4', ST_asEWKT(ST_GeomFromEWKB(decode('0109000000020000000102000000030000009FE5797057376340E09398B1B2373BC05AAE0A165F0963409F6760A2493D3DC0DB6286DFB057634082D8A1B32F843EC0010800000005000000DB6286DFB057634082D8A1B32F843EC0DB6286DFB057634082D8A1B32F843EC075B4E4D0C60C634031FA5D1A371540C0D7197CED9B636340A3CB59A7630A41C050F4A72AC0FB6240974769FCE3CF41C0', 'hex')));
SELECT 'valid wkb compound curve 5', ST_asEWKT(ST_GeomFromEWKB(decode('010900000003000000010800000003000000468280E724BC6340BF4B46210B973BC0F890AEA18D8063402D9664151D483CC0EED64BB6EE726340903CA5BDA0863AC0010200000004000000EED64BB6EE726340903CA5BDA0863AC09FE5797057376340E09398B1B2373BC05AAE0A165F0963409F6760A2493D3DC0DB6286DFB057634082D8A1B32F843EC0010800000005000000DB6286DFB057634082D8A1B32F843EC0DB6286DFB057634082D8A1B32F843EC075B4E4D0C60C634031FA5D1A371540C0D7197CED9B636340A3CB59A7630A41C050F4A72AC0FB6240974769FCE3CF41C0', 'hex')));
-SELECT 'null response', ST_NumPoints(ST_GeomFromEWKT('COMPOUNDCURVE(CIRCULARSTRING(0 0,2 0, 2 1, 2 3, 4 3),(4 3, 4 5, 1 4, 0 0))'));
+SELECT 'st_numpoints', ST_NumPoints(ST_GeomFromEWKT('COMPOUNDCURVE(CIRCULARSTRING(0 0,2 0, 2 1, 2 3, 4 3),(4 3, 4 5, 1 4, 0 0))'));
SELECT 'minpoints issues - pass', encode(ST_AsBinary(ST_GeomFromText('COMPOUNDCURVE((0 0,1 1))'),'ndr'),'hex');
SELECT 'minpoints issues - pass', encode(ST_AsBinary(ST_GeomFromText('COMPOUNDCURVE(CIRCULARSTRING(0 0,0 1,1 1))'),'ndr'),'hex');
SELECT 'minpoints issues - fail', ST_GeomFromText('COMPOUNDCURVE(CIRCULARSTRING(0 0,1 1))');
valid wkb compound curve 3|COMPOUNDCURVE((151.60117699 -27.32398274,151.22873381 -35.9433821,150.74987829 -27.80283826))
valid wkb compound curve 4|COMPOUNDCURVE((153.72942375 -27.2175704,152.29285719 -29.23940482,154.74034096 -30.51635287),CIRCULARSTRING(154.74034096 -30.51635287,154.74034096 -30.51635287,152.39926953 -32.16574411,155.11278414 -34.08116619,151.86720784 -35.62414508))
valid wkb compound curve 5|COMPOUNDCURVE(CIRCULARSTRING(157.87950492 -27.59001358,156.01728901 -28.28169378,155.59163966 -26.52589021),(155.59163966 -26.52589021,153.72942375 -27.2175704,152.29285719 -29.23940482,154.74034096 -30.51635287),CIRCULARSTRING(154.74034096 -30.51635287,154.74034096 -30.51635287,152.39926953 -32.16574411,155.11278414 -34.08116619,151.86720784 -35.62414508))
-null response|
+st_numpoints|9
minpoints issues - pass|01090000000100000001020000000200000000000000000000000000000000000000000000000000f03f000000000000f03f
minpoints issues - pass|010900000001000000010800000003000000000000000000000000000000000000000000000000000000000000000000f03f000000000000f03f000000000000f03f
ERROR: geometry requires more points
SELECT '#2712', ST_AsText(ST_Segmentize('LINESTRING EMPTY'::geometry, 0.5));
+SELECT '#2717',
+ ST_AsText(ST_StartPoint(g)),
+ ST_AsText(ST_EndPoint(g)),
+ ST_AsText(ST_PointN(g, 1)),
+ ST_AsText(ST_PointN(g, 2)),
+ ST_AsText(ST_PointN(g, 3)),
+ ST_AsText(ST_PointN(g, 4)),
+ ST_AsText(ST_PointN(g, 5))
+ FROM (
+ SELECT 'COMPOUNDCURVE((-1 -1, 1 1), CIRCULARSTRING(1 1, 2 2, 3 1))'::geometry AS g
+ ) AS foo;
+
SELECT '#2788', valid, reason, ST_AsText(location) from ST_IsValidDetail('POLYGON((0 0, 0 1, 2 1, 2 2, 1 2, 1 0, 0 0))'::geometry);
SELECT '#2870', ST_Summary('Point(151.215289 -33.856885)'::geometry::bytea::geography) ;
#2556|1|0
#2704|POLYGON((0 0,0 1,1 1,1 0,0 0))
#2712|LINESTRING EMPTY
+#2717|POINT(-1 -1)|POINT(3 1)|POINT(-1 -1)|POINT(1 1)|POINT(1 1)|POINT(2 2)|POINT(3 1)
#2788|f|Self-intersection|POINT(1 1)
#2870|Point[GS]
#2956|t