From: Olivier Courtin Date: Tue, 23 Feb 2010 18:29:00 +0000 (+0000) Subject: Move ptarray reverse axis function from postgis/lwgeom_in_gml to liblwgeom/ptarray X-Git-Tag: 2.0.0alpha1~3190 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b1aee9da3fc81eb90e250ca1ab04bf6e2ea6d732;p=postgis Move ptarray reverse axis function from postgis/lwgeom_in_gml to liblwgeom/ptarray git-svn-id: http://svn.osgeo.org/postgis/trunk@5319 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/liblwgeom.h b/liblwgeom/liblwgeom.h index dfbdb7e3c..20035595b 100644 --- a/liblwgeom/liblwgeom.h +++ b/liblwgeom/liblwgeom.h @@ -1382,6 +1382,8 @@ extern void ptarray_longitude_shift(POINTARRAY *pa); extern int32 lwgeom_nrings_recursive(uchar *serialized); extern void ptarray_reverse(POINTARRAY *pa); +extern POINTARRAY* ptarray_reverse_axis(POINTARRAY *pa); + extern POINTARRAY *ptarray_substring(POINTARRAY *, double, double); extern double ptarray_locate_point(POINTARRAY *, POINT2D *); extern void closest_point_on_segment(POINT2D *p, POINT2D *A, POINT2D *B, POINT2D *ret); diff --git a/liblwgeom/ptarray.c b/liblwgeom/ptarray.c index 375f2543c..9265207f9 100644 --- a/liblwgeom/ptarray.c +++ b/liblwgeom/ptarray.c @@ -73,6 +73,30 @@ ptarray_reverse(POINTARRAY *pa) } + +/** + * Reverse X and Y axis on a given POINTARRAY + */ +POINTARRAY* +ptarray_reverse_axis(POINTARRAY *pa) +{ + int i; + double d; + POINT4D p; + + for (i=0 ; i < pa->npoints ; i++) + { + getPoint4d_p(pa, i, &p); + d = p.y; + p.y = p.x; + p.x = d; + setPoint4d(pa, i, &p); + } + + return pa; +} + + /** * @brief calculate the 2d bounding box of a set of points * write result to the provided BOX2DFLOAT4 diff --git a/postgis/lwgeom_in_gml.c b/postgis/lwgeom_in_gml.c index 8f4d795f8..9d5718636 100644 --- a/postgis/lwgeom_in_gml.c +++ b/postgis/lwgeom_in_gml.c @@ -299,28 +299,6 @@ static xmlNodePtr get_xlink_node(xmlNodePtr xnode) } -/** - * Reverse X and Y axis on a given POINTARRAY - */ -static POINTARRAY* gml_reverse_axis_pa(POINTARRAY *pa) -{ - int i; - double d; - POINT4D p; - - for (i=0 ; i < pa->npoints ; i++) - { - getPoint4d_p(pa, i, &p); - d = p.y; - p.y = p.x; - p.x = d; - setPoint4d(pa, i, &p); - } - - return pa; -} - - /** * Use Proj4 to reproject a given POINTARRAY */ @@ -977,7 +955,7 @@ static POINTARRAY* parse_gml_data(xmlNodePtr xnode, bool *hasz, int *root_srid) lwerror("invalid GML representation"); srs = parse_gml_srs(xb); - if (srs->reverse_axis) tmp_pa = gml_reverse_axis_pa(tmp_pa); + if (srs->reverse_axis) tmp_pa = ptarray_reverse_axis(tmp_pa); if (!*root_srid) *root_srid = srs->srid; else { @@ -1012,7 +990,7 @@ static LWGEOM* parse_gml_point(xmlNodePtr xnode, bool *hasz, int *root_srid) if (pa->npoints != 1) lwerror("invalid GML representation"); srs = parse_gml_srs(xnode); - if (srs->reverse_axis) pa = gml_reverse_axis_pa(pa); + if (srs->reverse_axis) pa = ptarray_reverse_axis(pa); if (!*root_srid) { *root_srid = srs->srid; @@ -1046,7 +1024,7 @@ static LWGEOM* parse_gml_line(xmlNodePtr xnode, bool *hasz, int *root_srid) if (pa->npoints < 2) lwerror("invalid GML representation"); srs = parse_gml_srs(xnode); - if (srs->reverse_axis) pa = gml_reverse_axis_pa(pa); + if (srs->reverse_axis) pa = ptarray_reverse_axis(pa); if (!*root_srid) { *root_srid = srs->srid; @@ -1162,7 +1140,7 @@ static LWGEOM* parse_gml_curve(xmlNodePtr xnode, bool *hasz, int *root_srid) } srs = parse_gml_srs(xnode); - if (srs->reverse_axis) pa = gml_reverse_axis_pa(pa); + if (srs->reverse_axis) pa = ptarray_reverse_axis(pa); if (!*root_srid) { *root_srid = srs->srid; @@ -1219,7 +1197,7 @@ static LWGEOM* parse_gml_polygon(xmlNodePtr xnode, bool *hasz, int *root_srid) || (*hasz && !ptarray_isclosed3d(ppa[0]))) lwerror("invalid GML representation"); - if (srs->reverse_axis) ppa[0] = gml_reverse_axis_pa(ppa[0]); + if (srs->reverse_axis) ppa[0] = ptarray_reverse_axis(ppa[0]); } } @@ -1249,7 +1227,7 @@ static LWGEOM* parse_gml_polygon(xmlNodePtr xnode, bool *hasz, int *root_srid) || (*hasz && !ptarray_isclosed3d(ppa[ring]))) lwerror("invalid GML representation"); - if (srs->reverse_axis) ppa[ring] = gml_reverse_axis_pa(ppa[ring]); + if (srs->reverse_axis) ppa[ring] = ptarray_reverse_axis(ppa[ring]); ring++; } } @@ -1350,7 +1328,7 @@ static LWGEOM* parse_gml_surface(xmlNodePtr xnode, bool *hasz, int *root_srid) || (*hasz && !ptarray_isclosed3d(ppa[0]))) lwerror("invalid GML representation"); - if (srs->reverse_axis) ppa[0] = gml_reverse_axis_pa(ppa[0]); + if (srs->reverse_axis) ppa[0] = ptarray_reverse_axis(ppa[0]); } } @@ -1378,7 +1356,7 @@ static LWGEOM* parse_gml_surface(xmlNodePtr xnode, bool *hasz, int *root_srid) lwerror("invalid GML representation"); if (srs->reverse_axis) - ppa[ring] = gml_reverse_axis_pa(ppa[ring]); + ppa[ring] = ptarray_reverse_axis(ppa[ring]); ring++; }