]> granicus.if.org Git - postgis/commitdiff
Added runtime cast functions.
authorSandro Santilli <strk@keybit.net>
Fri, 1 Oct 2004 07:51:00 +0000 (07:51 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 1 Oct 2004 07:51:00 +0000 (07:51 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@917 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/liblwgeom.h
lwgeom/lwgeom.c

index bf0ba3e8c1fd3a03c885d8e74f2d5f4b1b1e33c1..1bc4e0d6c8e7eb8caeab6ecdd33480373fac52e0 100644 (file)
@@ -225,6 +225,23 @@ typedef struct
        LWGEOM **geoms;
 } LWCOLLECTION; 
 
+// Casts LWGEOM->LW* (return NULL if cast is illegal)
+LWMPOLY *lwgeom_as_lwmpoly(LWGEOM *lwgeom);
+LWMLINE *lwgeom_as_lwmline(LWGEOM *lwgeom);
+LWMPOINT *lwgeom_as_lwmpoint(LWGEOM *lwgeom);
+LWCOLLECTION *lwgeom_as_lwcollection(LWGEOM *lwgeom);
+LWPOLY *lwgeom_as_lwpoly(LWGEOM *lwgeom);
+LWLINE *lwgeom_as_lwline(LWGEOM *lwgeom);
+LWPOINT *lwgeom_as_lwpoint(LWGEOM *lwgeom);
+
+// Casts LW*->LWGEOM (always cast)
+LWGEOM *lwmpoly_as_lwgeom(LWMPOLY *obj);
+LWGEOM *lwmline_as_lwgeom(LWMLINE *obj);
+LWGEOM *lwmpoint_as_lwgeom(LWMPOINT *obj);
+LWGEOM *lwcollection_as_lwgeom(LWCOLLECTION *obj);
+LWGEOM *lwpoly_as_lwgeom(LWPOLY *obj);
+LWGEOM *lwline_as_lwgeom(LWLINE *obj);
+LWGEOM *lwpoint_as_lwgeom(LWPOINT *obj);
 //-------------------------------------------------------------
 
 // copies a point from the point array into the parameter point
index 6f01ad70e55659770b38f561190483b3026c9702..bc96c441830babad35790c6ce15856cda3cdd587 100644 (file)
@@ -185,3 +185,60 @@ lwgeom_compute_bbox(LWGEOM *lwgeom)
        if ( lwgeom_compute_bbox_p(lwgeom, result) ) return result;
        else return NULL;
 }
+
+LWPOINT *
+lwgeom_as_lwpoint(LWGEOM *lwgeom)
+{
+       if ( lwgeom->type == POINTTYPE ) return (LWPOINT *)lwgeom;
+       else return NULL;
+}
+
+LWLINE *
+lwgeom_as_lwline(LWGEOM *lwgeom)
+{
+       if ( lwgeom->type == LINETYPE ) return (LWLINE *)lwgeom;
+       else return NULL;
+}
+
+LWPOLY *
+lwgeom_as_lwpoly(LWGEOM *lwgeom)
+{
+       if ( lwgeom->type == POLYGONTYPE ) return (LWPOLY *)lwgeom;
+       else return NULL;
+}
+
+LWCOLLECTION *
+lwgeom_as_lwcollection(LWGEOM *lwgeom)
+{
+       if ( lwgeom->type >= MULTIPOINTTYPE ) return (LWCOLLECTION *)lwgeom;
+       else return NULL;
+}
+
+LWMPOINT *
+lwgeom_as_lwmpoint(LWGEOM *lwgeom)
+{
+       if ( lwgeom->type == MULTIPOINTTYPE ) return (LWMPOINT *)lwgeom;
+       else return NULL;
+}
+
+LWMLINE *
+lwgeom_as_lwmline(LWGEOM *lwgeom)
+{
+       if ( lwgeom->type == MULTILINETYPE ) return (LWMLINE *)lwgeom;
+       else return NULL;
+}
+
+LWMPOLY *
+lwgeom_as_lwmpoly(LWGEOM *lwgeom)
+{
+       if ( lwgeom->type == MULTIPOLYGONTYPE ) return (LWMPOLY *)lwgeom;
+       else return NULL;
+}
+
+LWGEOM *lwmpoly_as_lwgeom(LWMPOLY *obj) { return (LWGEOM *)obj; }
+LWGEOM *lwmline_as_lwgeom(LWMLINE *obj) { return (LWGEOM *)obj; }
+LWGEOM *lwmpoint_as_lwgeom(LWMPOINT *obj) { return (LWGEOM *)obj; }
+LWGEOM *lwcollection_as_lwgeom(LWCOLLECTION *obj) { return (LWGEOM *)obj; }
+LWGEOM *lwpoly_as_lwgeom(LWPOLY *obj) { return (LWGEOM *)obj; }
+LWGEOM *lwline_as_lwgeom(LWLINE *obj) { return (LWGEOM *)obj; }
+LWGEOM *lwpoint_as_lwgeom(LWPOINT *obj) { return (LWGEOM *)obj; }