From: Andrea Zagli Date: Sun, 21 Jun 2009 17:19:58 +0000 (+0200) Subject: Continued base classes. X-Git-Tag: GTKGIS_0_0_1~11 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=0cce0e512abe0fe6e99e503df0556724e23e1dbe;p=libgtkgis Continued base classes. Added gtkgis.dtd. --- diff --git a/Makefile.am b/Makefile.am index e4af899..e9e5101 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS=-I m4 DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc -SUBDIRS = src tests +SUBDIRS = src data tests EXTRA_DIST = libgtkgis.pc.in diff --git a/configure.ac b/configure.ac index 29dc4a6..c050dc5 100644 --- a/configure.ac +++ b/configure.ac @@ -52,6 +52,7 @@ AC_CONFIG_FILES([ libgtkgis.pc Makefile src/Makefile + data/Makefile tests/Makefile ]) AC_OUTPUT diff --git a/data/Makefile.am b/data/Makefile.am new file mode 100644 index 0000000..ffc0d6c --- /dev/null +++ b/data/Makefile.am @@ -0,0 +1,2 @@ +EXTRA_DIST = \ + gtkgis.dtd diff --git a/data/gtkgis.dtd b/data/gtkgis.dtd new file mode 100644 index 0000000..43ad2bc --- /dev/null +++ b/data/gtkgis.dtd @@ -0,0 +1,21 @@ + + + + + + + + + + + + diff --git a/src/Makefile.am b/src/Makefile.am index 753e687..2cd0b81 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,7 +15,11 @@ libgtkgis_la_SOURCES = \ layersource.c \ layersourceshp.c \ layersourcepostgis.c \ - geometry.c + geometry.c \ + geometrypoint.c \ + geometryline.c \ + geometrypolygon.c \ + geometryraster.c include_HEADERS = \ libgtkgis.h \ @@ -24,7 +28,10 @@ include_HEADERS = \ layersource.h \ layersourceshp.h \ layersourcepostgis.h \ - geometry.h - + geometry.h \ + geometrypoint.h \ + geometryline.h \ + geometrypolygon.h \ + geometryraster.h noinst_HEADERS = diff --git a/src/geometryline.c b/src/geometryline.c new file mode 100644 index 0000000..3a5b6b1 --- /dev/null +++ b/src/geometryline.c @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2009 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include +#include + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include "geometryline.h" + +static void gtk_gis_geometry_line_class_init (GtkGisGeometryLineClass *klass); +static void gtk_gis_geometry_line_init (GtkGisGeometryLine *gtk_gis_geometry_line); + +static void gtk_gis_geometry_line_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void gtk_gis_geometry_line_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + + +#define GTK_GIS_GEOMETRY_LINE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_GIS_GEOMETRY_LINE, GtkGisGeometryLinePrivate)) + +typedef struct _GtkGisGeometryLinePrivate GtkGisGeometryLinePrivate; +struct _GtkGisGeometryLinePrivate + { + }; + +GType +gtk_gis_geometry_line_get_type (void) +{ + static GType gtk_gis_geometry_line_type = 0; + + if (!gtk_gis_geometry_line_type) + { + static const GTypeInfo gtk_gis_geometry_line_info = + { + sizeof (GtkGisGeometryLineClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) gtk_gis_geometry_line_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GtkGisGeometryLine), + 0, /* n_preallocs */ + (GInstanceInitFunc) gtk_gis_geometry_line_init, + NULL + }; + + gtk_gis_geometry_line_type = g_type_register_static (G_TYPE_OBJECT, "GtkGisGeometryLine", + >k_gis_geometry_line_info, 0); + } + + return gtk_gis_geometry_line_type; +} + +static void +gtk_gis_geometry_line_class_init (GtkGisGeometryLineClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (GtkGisGeometryLinePrivate)); + + object_class->set_property = gtk_gis_geometry_line_set_property; + object_class->get_property = gtk_gis_geometry_line_get_property; +} + +static void +gtk_gis_geometry_line_init (GtkGisGeometryLine *gtk_gis_geometry_line) +{ + GtkGisGeometryLinePrivate *priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (gtk_gis_geometry_line); +} + +/** + * gtk_gis_geometry_line_new: + * + * Creates a new #GtkGisGeometryLine object. + * + * Returns: the newly created #GtkGisGeometryLine object. + */ +GtkGisGeometryLine +*gtk_gis_geometry_line_new () +{ + GtkGisGeometryLine *gtk_gis_geometry_line; + + gtk_gis_geometry_line = GTK_GIS_GEOMETRY_LINE (g_object_new (gtk_gis_geometry_line_get_type (), NULL)); + + return gtk_gis_geometry_line; +} + +static void +gtk_gis_geometry_line_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + GtkGisGeometryLine *gtk_gis_geometry_line = GTK_GIS_GEOMETRY_LINE (object); + + GtkGisGeometryLinePrivate *priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (gtk_gis_geometry_line); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gtk_gis_geometry_line_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + GtkGisGeometryLine *gtk_gis_geometry_line = GTK_GIS_GEOMETRY_LINE (object); + + GtkGisGeometryLinePrivate *priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (gtk_gis_geometry_line); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} diff --git a/src/geometryline.h b/src/geometryline.h new file mode 100644 index 0000000..0383fb2 --- /dev/null +++ b/src/geometryline.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2009 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __GTK_GIS_GEOMETRY_LINE_H__ +#define __GTK_GIS_GEOMETRY_LINE_H__ + +#include "geometry.h" + +G_BEGIN_DECLS + + +#define TYPE_GTK_GIS_GEOMETRY_LINE (gtk_gis_geometry_line_get_type ()) +#define GTK_GIS_GEOMETRY_LINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GTK_GIS_GEOMETRY_LINE, GtkGisGeometryLine)) +#define GTK_GIS_GEOMETRY_LINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GTK_GIS_GEOMETRY_LINE, GtkGisGeometryLineClass)) +#define IS_GTK_GIS_GEOMETRY_LINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GTK_GIS_GEOMETRY_LINE)) +#define IS_GTK_GIS_GEOMETRY_LINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GTK_GIS_GEOMETRY_LINE)) +#define GTK_GIS_GEOMETRY_LINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GTK_GIS_GEOMETRY_LINE, GtkGisGeometryLineClass)) + + +typedef struct _GtkGisGeometryLine GtkGisGeometryLine; +typedef struct _GtkGisGeometryLineClass GtkGisGeometryLineClass; + +struct _GtkGisGeometryLine + { + GtkGisGeometry parent; + }; + +struct _GtkGisGeometryLineClass + { + GtkGisGeometryClass parent_class; + }; + +GType gtk_gis_geometry_line_get_type (void) G_GNUC_CONST; + + +GtkGisGeometryLine *gtk_gis_geometry_line_new (void); + + +G_END_DECLS + +#endif /* __GTK_GIS_GEOMETRY_LINE_H__ */ diff --git a/src/geometrypoint.c b/src/geometrypoint.c new file mode 100644 index 0000000..eb3519f --- /dev/null +++ b/src/geometrypoint.c @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2009 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include +#include + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include "geometrypoint.h" + +static void gtk_gis_geometry_point_class_init (GtkGisGeometryPointClass *klass); +static void gtk_gis_geometry_point_init (GtkGisGeometryPoint *gtk_gis_geometry_point); + +static void gtk_gis_geometry_point_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void gtk_gis_geometry_point_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + + +#define GTK_GIS_GEOMETRY_POINT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_GIS_GEOMETRY_POINT, GtkGisGeometryPointPrivate)) + +typedef struct _GtkGisGeometryPointPrivate GtkGisGeometryPointPrivate; +struct _GtkGisGeometryPointPrivate + { + }; + +GType +gtk_gis_geometry_point_get_type (void) +{ + static GType gtk_gis_geometry_point_type = 0; + + if (!gtk_gis_geometry_point_type) + { + static const GTypeInfo gtk_gis_geometry_point_info = + { + sizeof (GtkGisGeometryPointClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) gtk_gis_geometry_point_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GtkGisGeometryPoint), + 0, /* n_preallocs */ + (GInstanceInitFunc) gtk_gis_geometry_point_init, + NULL + }; + + gtk_gis_geometry_point_type = g_type_register_static (G_TYPE_OBJECT, "GtkGisGeometryPoint", + >k_gis_geometry_point_info, 0); + } + + return gtk_gis_geometry_point_type; +} + +static void +gtk_gis_geometry_point_class_init (GtkGisGeometryPointClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (GtkGisGeometryPointPrivate)); + + object_class->set_property = gtk_gis_geometry_point_set_property; + object_class->get_property = gtk_gis_geometry_point_get_property; +} + +static void +gtk_gis_geometry_point_init (GtkGisGeometryPoint *gtk_gis_geometry_point) +{ + GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (gtk_gis_geometry_point); +} + +/** + * gtk_gis_geometry_point_new: + * + * Creates a new #GtkGisGeometryPoint object. + * + * Returns: the newly created #GtkGisGeometryPoint object. + */ +GtkGisGeometryPoint +*gtk_gis_geometry_point_new () +{ + GtkGisGeometryPoint *gtk_gis_geometry_point; + + gtk_gis_geometry_point = GTK_GIS_GEOMETRY_POINT (g_object_new (gtk_gis_geometry_point_get_type (), NULL)); + + return gtk_gis_geometry_point; +} + +static void +gtk_gis_geometry_point_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + GtkGisGeometryPoint *gtk_gis_geometry_point = GTK_GIS_GEOMETRY_POINT (object); + + GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (gtk_gis_geometry_point); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gtk_gis_geometry_point_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + GtkGisGeometryPoint *gtk_gis_geometry_point = GTK_GIS_GEOMETRY_POINT (object); + + GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (gtk_gis_geometry_point); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} diff --git a/src/geometrypoint.h b/src/geometrypoint.h new file mode 100644 index 0000000..15eec16 --- /dev/null +++ b/src/geometrypoint.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2009 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __GTK_GIS_GEOMETRY_POINT_H__ +#define __GTK_GIS_GEOMETRY_POINT_H__ + +#include "geometry.h" + +G_BEGIN_DECLS + + +#define TYPE_GTK_GIS_GEOMETRY_POINT (gtk_gis_geometry_point_get_type ()) +#define GTK_GIS_GEOMETRY_POINT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GTK_GIS_GEOMETRY_POINT, GtkGisGeometryPoint)) +#define GTK_GIS_GEOMETRY_POINT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GTK_GIS_GEOMETRY_POINT, GtkGisGeometryPointClass)) +#define IS_GTK_GIS_GEOMETRY_POINT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GTK_GIS_GEOMETRY_POINT)) +#define IS_GTK_GIS_GEOMETRY_POINT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GTK_GIS_GEOMETRY_POINT)) +#define GTK_GIS_GEOMETRY_POINT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GTK_GIS_GEOMETRY_POINT, GtkGisGeometryPointClass)) + + +typedef struct _GtkGisGeometryPoint GtkGisGeometryPoint; +typedef struct _GtkGisGeometryPointClass GtkGisGeometryPointClass; + +struct _GtkGisGeometryPoint + { + GtkGisGeometry parent; + }; + +struct _GtkGisGeometryPointClass + { + GtkGisGeometryClass parent_class; + }; + +GType gtk_gis_geometry_point_get_type (void) G_GNUC_CONST; + + +GtkGisGeometryPoint *gtk_gis_geometry_point_new (void); + + +G_END_DECLS + +#endif /* __GTK_GIS_GEOMETRY_POINT_H__ */ diff --git a/src/geometrypolygon.c b/src/geometrypolygon.c new file mode 100644 index 0000000..bfb4af9 --- /dev/null +++ b/src/geometrypolygon.c @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2009 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include +#include + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include "geometrypolygon.h" + +static void gtk_gis_geometry_polygon_class_init (GtkGisGeometryPolygonClass *klass); +static void gtk_gis_geometry_polygon_init (GtkGisGeometryPolygon *gtk_gis_geometry_polygon); + +static void gtk_gis_geometry_polygon_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void gtk_gis_geometry_polygon_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + + +#define GTK_GIS_GEOMETRY_POLYGON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_GIS_GEOMETRY_POLYGON, GtkGisGeometryPolygonPrivate)) + +typedef struct _GtkGisGeometryPolygonPrivate GtkGisGeometryPolygonPrivate; +struct _GtkGisGeometryPolygonPrivate + { + }; + +GType +gtk_gis_geometry_polygon_get_type (void) +{ + static GType gtk_gis_geometry_polygon_type = 0; + + if (!gtk_gis_geometry_polygon_type) + { + static const GTypeInfo gtk_gis_geometry_polygon_info = + { + sizeof (GtkGisGeometryPolygonClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) gtk_gis_geometry_polygon_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GtkGisGeometryPolygon), + 0, /* n_preallocs */ + (GInstanceInitFunc) gtk_gis_geometry_polygon_init, + NULL + }; + + gtk_gis_geometry_polygon_type = g_type_register_static (G_TYPE_OBJECT, "GtkGisGeometryPolygon", + >k_gis_geometry_polygon_info, 0); + } + + return gtk_gis_geometry_polygon_type; +} + +static void +gtk_gis_geometry_polygon_class_init (GtkGisGeometryPolygonClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (GtkGisGeometryPolygonPrivate)); + + object_class->set_property = gtk_gis_geometry_polygon_set_property; + object_class->get_property = gtk_gis_geometry_polygon_get_property; +} + +static void +gtk_gis_geometry_polygon_init (GtkGisGeometryPolygon *gtk_gis_geometry_polygon) +{ + GtkGisGeometryPolygonPrivate *priv = GTK_GIS_GEOMETRY_POLYGON_GET_PRIVATE (gtk_gis_geometry_polygon); +} + +/** + * gtk_gis_geometry_polygon_new: + * + * Creates a new #GtkGisGeometryPolygon object. + * + * Returns: the newly created #GtkGisGeometryPolygon object. + */ +GtkGisGeometryPolygon +*gtk_gis_geometry_polygon_new () +{ + GtkGisGeometryPolygon *gtk_gis_geometry_polygon; + + gtk_gis_geometry_polygon = GTK_GIS_GEOMETRY_POLYGON (g_object_new (gtk_gis_geometry_polygon_get_type (), NULL)); + + return gtk_gis_geometry_polygon; +} + +static void +gtk_gis_geometry_polygon_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + GtkGisGeometryPolygon *gtk_gis_geometry_polygon = GTK_GIS_GEOMETRY_POLYGON (object); + + GtkGisGeometryPolygonPrivate *priv = GTK_GIS_GEOMETRY_POLYGON_GET_PRIVATE (gtk_gis_geometry_polygon); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gtk_gis_geometry_polygon_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + GtkGisGeometryPolygon *gtk_gis_geometry_polygon = GTK_GIS_GEOMETRY_POLYGON (object); + + GtkGisGeometryPolygonPrivate *priv = GTK_GIS_GEOMETRY_POLYGON_GET_PRIVATE (gtk_gis_geometry_polygon); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} diff --git a/src/geometrypolygon.h b/src/geometrypolygon.h new file mode 100644 index 0000000..2b740e9 --- /dev/null +++ b/src/geometrypolygon.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2009 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __GTK_GIS_GEOMETRY_POLYGON_H__ +#define __GTK_GIS_GEOMETRY_POLYGON_H__ + +#include "geometry.h" + +G_BEGIN_DECLS + + +#define TYPE_GTK_GIS_GEOMETRY_POLYGON (gtk_gis_geometry_polygon_get_type ()) +#define GTK_GIS_GEOMETRY_POLYGON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GTK_GIS_GEOMETRY_POLYGON, GtkGisGeometryPolygon)) +#define GTK_GIS_GEOMETRY_POLYGON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GTK_GIS_GEOMETRY_POLYGON, GtkGisGeometryPolygonClass)) +#define IS_GTK_GIS_GEOMETRY_POLYGON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GTK_GIS_GEOMETRY_POLYGON)) +#define IS_GTK_GIS_GEOMETRY_POLYGON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GTK_GIS_GEOMETRY_POLYGON)) +#define GTK_GIS_GEOMETRY_POLYGON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GTK_GIS_GEOMETRY_POLYGON, GtkGisGeometryPolygonClass)) + + +typedef struct _GtkGisGeometryPolygon GtkGisGeometryPolygon; +typedef struct _GtkGisGeometryPolygonClass GtkGisGeometryPolygonClass; + +struct _GtkGisGeometryPolygon + { + GtkGisGeometry parent; + }; + +struct _GtkGisGeometryPolygonClass + { + GtkGisGeometryClass parent_class; + }; + +GType gtk_gis_geometry_polygon_get_type (void) G_GNUC_CONST; + + +GtkGisGeometryPolygon *gtk_gis_geometry_polygon_new (void); + + +G_END_DECLS + +#endif /* __GTK_GIS_GEOMETRY_POLYGON_H__ */ diff --git a/src/geometryraster.c b/src/geometryraster.c new file mode 100644 index 0000000..4fe3800 --- /dev/null +++ b/src/geometryraster.c @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2009 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include +#include + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include "geometryraster.h" + +static void gtk_gis_geometry_raster_class_init (GtkGisGeometryRasterClass *klass); +static void gtk_gis_geometry_raster_init (GtkGisGeometryRaster *gtk_gis_geometry_raster); + +static void gtk_gis_geometry_raster_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void gtk_gis_geometry_raster_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + + +#define GTK_GIS_GEOMETRY_RASTER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_GIS_GEOMETRY_RASTER, GtkGisGeometryRasterPrivate)) + +typedef struct _GtkGisGeometryRasterPrivate GtkGisGeometryRasterPrivate; +struct _GtkGisGeometryRasterPrivate + { + }; + +GType +gtk_gis_geometry_raster_get_type (void) +{ + static GType gtk_gis_geometry_raster_type = 0; + + if (!gtk_gis_geometry_raster_type) + { + static const GTypeInfo gtk_gis_geometry_raster_info = + { + sizeof (GtkGisGeometryRasterClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) gtk_gis_geometry_raster_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GtkGisGeometryRaster), + 0, /* n_preallocs */ + (GInstanceInitFunc) gtk_gis_geometry_raster_init, + NULL + }; + + gtk_gis_geometry_raster_type = g_type_register_static (G_TYPE_OBJECT, "GtkGisGeometryRaster", + >k_gis_geometry_raster_info, 0); + } + + return gtk_gis_geometry_raster_type; +} + +static void +gtk_gis_geometry_raster_class_init (GtkGisGeometryRasterClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (GtkGisGeometryRasterPrivate)); + + object_class->set_property = gtk_gis_geometry_raster_set_property; + object_class->get_property = gtk_gis_geometry_raster_get_property; +} + +static void +gtk_gis_geometry_raster_init (GtkGisGeometryRaster *gtk_gis_geometry_raster) +{ + GtkGisGeometryRasterPrivate *priv = GTK_GIS_GEOMETRY_RASTER_GET_PRIVATE (gtk_gis_geometry_raster); +} + +/** + * gtk_gis_geometry_raster_new: + * + * Creates a new #GtkGisGeometryRaster object. + * + * Returns: the newly created #GtkGisGeometryRaster object. + */ +GtkGisGeometryRaster +*gtk_gis_geometry_raster_new () +{ + GtkGisGeometryRaster *gtk_gis_geometry_raster; + + gtk_gis_geometry_raster = GTK_GIS_GEOMETRY_RASTER (g_object_new (gtk_gis_geometry_raster_get_type (), NULL)); + + return gtk_gis_geometry_raster; +} + +static void +gtk_gis_geometry_raster_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + GtkGisGeometryRaster *gtk_gis_geometry_raster = GTK_GIS_GEOMETRY_RASTER (object); + + GtkGisGeometryRasterPrivate *priv = GTK_GIS_GEOMETRY_RASTER_GET_PRIVATE (gtk_gis_geometry_raster); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gtk_gis_geometry_raster_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + GtkGisGeometryRaster *gtk_gis_geometry_raster = GTK_GIS_GEOMETRY_RASTER (object); + + GtkGisGeometryRasterPrivate *priv = GTK_GIS_GEOMETRY_RASTER_GET_PRIVATE (gtk_gis_geometry_raster); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} diff --git a/src/geometryraster.h b/src/geometryraster.h new file mode 100644 index 0000000..e8ac4e9 --- /dev/null +++ b/src/geometryraster.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2009 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __GTK_GIS_GEOMETRY_RASTER_H__ +#define __GTK_GIS_GEOMETRY_RASTER_H__ + +#include "geometry.h" + +G_BEGIN_DECLS + + +#define TYPE_GTK_GIS_GEOMETRY_RASTER (gtk_gis_geometry_raster_get_type ()) +#define GTK_GIS_GEOMETRY_RASTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GTK_GIS_GEOMETRY_RASTER, GtkGisGeometryRaster)) +#define GTK_GIS_GEOMETRY_RASTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GTK_GIS_GEOMETRY_RASTER, GtkGisGeometryRasterClass)) +#define IS_GTK_GIS_GEOMETRY_RASTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GTK_GIS_GEOMETRY_RASTER)) +#define IS_GTK_GIS_GEOMETRY_RASTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GTK_GIS_GEOMETRY_RASTER)) +#define GTK_GIS_GEOMETRY_RASTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GTK_GIS_GEOMETRY_RASTER, GtkGisGeometryRasterClass)) + + +typedef struct _GtkGisGeometryRaster GtkGisGeometryRaster; +typedef struct _GtkGisGeometryRasterClass GtkGisGeometryRasterClass; + +struct _GtkGisGeometryRaster + { + GtkGisGeometry parent; + }; + +struct _GtkGisGeometryRasterClass + { + GtkGisGeometryClass parent_class; + }; + +GType gtk_gis_geometry_raster_get_type (void) G_GNUC_CONST; + + +GtkGisGeometryRaster *gtk_gis_geometry_raster_new (void); + + +G_END_DECLS + +#endif /* __GTK_GIS_GEOMETRY_RASTER_H__ */ diff --git a/src/layer.c b/src/layer.c index 446276d..bf15d64 100644 --- a/src/layer.c +++ b/src/layer.c @@ -45,7 +45,15 @@ static void gtk_gis_layer_get_property (GObject *object, typedef struct _GtkGisLayerPrivate GtkGisLayerPrivate; struct _GtkGisLayerPrivate { + gchar *name; + + GtkGisLayerGeometryType geometry_type; + + GtkGisLayerSource *source; + GList *geometries; + + gboolean editable; }; GType @@ -95,37 +103,71 @@ gtk_gis_layer_init (GtkGisLayer *gtk_gis_layer) /** * gtk_gis_layer_new: + * @source: * @name: * @geometrytype: - * @source: * - * Creates a new #GtkGisLayer object. + * Creates a new empty #GtkGisLayer object. * * Returns: the newly created #GtkGisLayer object. */ GtkGisLayer -*gtk_gis_layer_new (gchar *name, - GtkGisLayerGeometryType geometry_type, - GtkGisLayerSource *source) +*gtk_gis_layer_new (GtkGisLayerSource *source, + gchar *name, + GtkGisLayerGeometryType geometry_type) { GtkGisLayer *gtk_gis_layer; + GtkGisLayerPrivate *priv; gtk_gis_layer = GTK_GIS_LAYER (g_object_new (gtk_gis_layer_get_type (), NULL)); + priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + + priv->source = source; + priv->name = g_strdup (name); + priv->geometry_type = geometry_type; + + priv->editable = TRUE; + return gtk_gis_layer; } /** * gtk_gis_layer_new_from_source: * @source: + * @name: the layer's name to load. * * Creates a new #GtkGisLayer object and load its content from the #GtkGisLayerSource. * * Returns: the newly created #GtkGisLayer object. */ GtkGisLayer -*gtk_gis_layer_new_from_source (GtkGisLayerSource *source) +*gtk_gis_layer_new_from_source (GtkGisLayerSource *source, + gchar *name) { + GtkGisLayer *layer; + + GtkGisLayerGeometryType type; + + type = gtk_gis_layer_source_get_layer_geometry_type (source, name); + + layer = gtk_gis_layer_new (source, name, type); + + return layer; +} + +/** + * gtk_gis_layer_get_name: + * @layer: + * + * Returns: the #GtkGisLayer's name. + */ +gchar +*gtk_gis_layer_get_name (GtkGisLayer *layer) +{ + GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + + return g_strdup (priv->name); } /** @@ -137,11 +179,31 @@ GtkGisLayer GtkGisLayerSource *gtk_gis_layer_get_source (GtkGisLayer *layer) { + GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + + return priv->source; +} + +/** + * gtk_gis_layer_fill_from_source: + * @layer: + * + * Loads the #GtkGisLayer's content from the associated #GtkGisLayerSource. + * Contents loaded before will be lost. + */ +void +gtk_gis_layer_fill_from_source (GtkGisLayer *layer) +{ + GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + + gtk_gis_layer_source_fill_layer (priv->source, layer); } /** * gtk_gis_layer_save: * @layer: + * @source: The #GtkGisLayerSource to use. If NULL, it'll use the associated + * #GtkGisLayerSource. * * Save the #GtkGisLayer to the disk. */ @@ -186,6 +248,9 @@ gtk_gis_layer_remove_geometry (GtkGisLayer *layer, GtkGisGeometry *geometry) gboolean gtk_gis_layer_get_editable (GtkGisLayer *layer) { + GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + + return priv->editable; } /** @@ -197,6 +262,25 @@ void gtk_gis_layer_set_editable (GtkGisLayer *layer, gboolean editable) { + GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + + priv->editable = editable; +} + +/** + * gtk_gis_layer_draw: + * @layer: + * @canvas_root: + * + */ +void +gtk_gis_layer_draw (GtkGisLayer *layer + GooCanvasItem *canvas_root) +{ + if (IS_GTK_GIS_LAYER_OBJECT (layer) && GTK_GIS_LAYER_GET_CLASS (layer)->draw != NULL) + { + GTK_GIS_LAYER_GET_CLASS (layer)->draw (layer, canvas_root); + } } static void diff --git a/src/layer.h b/src/layer.h index e55ed73..407950f 100644 --- a/src/layer.h +++ b/src/layer.h @@ -23,6 +23,8 @@ #include #include +#include + #include "geometry.h" #include "layersource.h" @@ -61,14 +63,19 @@ typedef enum LAYER_GEOMETRY_TYPE_RASTER } GtkGisLayerGeometryType; -GtkGisLayer *gtk_gis_layer_new (gchar *name, - GtkGisLayerGeometryType geometry_type, - GtkGisLayerSource *source); +GtkGisLayer *gtk_gis_layer_new (GtkGisLayerSource *source, + gchar *name, + GtkGisLayerGeometryType geometry_type); + +GtkGisLayer *gtk_gis_layer_new_from_source (GtkGisLayerSource *source, + gchar *name); -GtkGisLayer *gtk_gis_layer_new_from_source (GtkGisLayerSource *source); +gchar *gtk_gis_layer_get_name (GtkGisLayer *layer); GtkGisLayerSource *gtk_gis_layer_get_source (GtkGisLayer *layer); +void gtk_gis_layer_fill_from_source (GtkGisLayer *layer); + void gtk_gis_layer_save (GtkGisLayer *layer, GtkGisLayerSource *source); @@ -81,6 +88,9 @@ gboolean gtk_gis_layer_get_editable (GtkGisLayer *layer); void gtk_gis_layer_set_editable (GtkGisLayer *layer, gboolean editable); +void gtk_gis_layer_draw (GtkGisLayer *layer + GooCanvasItem *canvas_root); + G_END_DECLS diff --git a/src/layersource.c b/src/layersource.c index b9edfcd..9d2649c 100644 --- a/src/layersource.c +++ b/src/layersource.c @@ -20,6 +20,9 @@ #include #endif +#include +#include + #include "layersource.h" static void gtk_gis_layer_source_class_init (GtkGisLayerSourceClass *klass); @@ -40,6 +43,7 @@ static void gtk_gis_layer_source_get_property (GObject *object, typedef struct _GtkGisLayerSourcePrivate GtkGisLayerSourcePrivate; struct _GtkGisLayerSourcePrivate { + OGRDataSourceH datasource; }; GType @@ -104,6 +108,47 @@ GtkGisLayerSource return gtk_gis_layer_source; } +/** + * gtk_gis_layer_source_load: + * @source: + * @layer: + * + */ +gboolean +gtk_gis_layer_source_fill_layer (GtkGisLayerSource *source, + GtkGisLayer *layer) +{ + gboolean ret = FALSE; + + if (IS_GTK_GIS_LAYER_SOURCE_OBJECT (source) && GTK_GIS_LAYER_SOURCE_GET_CLASS (source)->load != NULL) + { + ret = GTK_GIS_LAYER_SOURCE_GET_CLASS (source)->fill_layer (source, layer); + } + + return ret; +} + +/** + * gtk_gis_layer_source_get_layer_geometry_type: + * @source: + * @name: + * + * Returns: a #GtkGisLayerGeometryType or -1 on error. + */ +GtkGisLayerGeometryType +gtk_gis_layer_source_get_layer_geometry_type (GtkGisLayerSource *source, + gchar *name) +{ + GtkGisLayerGeometryType type = -1; + + if (IS_GTK_GIS_LAYER_SOURCE_OBJECT (source) && GTK_GIS_LAYER_SOURCE_GET_CLASS (source)->get_layer_geometry_type != NULL) + { + type = GTK_GIS_LAYER_SOURCE_GET_CLASS (source)->get_layer_geometry_type (source, name); + } + + return type; +} + static void gtk_gis_layer_source_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { diff --git a/src/layersource.h b/src/layersource.h index 2e8cb11..7bef22d 100644 --- a/src/layersource.h +++ b/src/layersource.h @@ -23,6 +23,8 @@ #include #include +#include "layer.h" + G_BEGIN_DECLS @@ -45,6 +47,12 @@ struct _GtkGisLayerSource struct _GtkGisLayerSourceClass { GObjectClass parent_class; + + gboolean (*fill_layer) (GtkGisLayerSource *source, + GtkGisLayer *layer); + + GtkGisLayerGeometryType (*get_layer_geometry_type) (GtkGisLayerSource *source, + gchar *name); }; GType gtk_gis_layer_source_get_type (void) G_GNUC_CONST; @@ -52,6 +60,12 @@ GType gtk_gis_layer_source_get_type (void) G_GNUC_CONST; GtkGisLayerSource *gtk_gis_layer_source_new (void); +gboolean gtk_gis_layer_source_fill_layer (GtkGisLayerSource *source, + GtkGisLayer *layer); + +GtkGisLayerGeometryType gtk_gis_layer_source_get_layer_geometry_type (GtkGisLayerSource *source, + gchar *name); + G_END_DECLS diff --git a/src/layersourcepostgis.c b/src/layersourcepostgis.c index 46e3539..6ec1326 100644 --- a/src/layersourcepostgis.c +++ b/src/layersourcepostgis.c @@ -89,18 +89,33 @@ gtk_gis_layer_source_postgis_init (GtkGisLayerSourcePostgis *gtk_gis_layer_sourc /** * gtk_gis_layer_source_postgis_new: + * @host: the host to connect. If #NULL equal to localhost. + * @port: the port where Postgres is. If 0 equale to 5432. + * @username: the username to use. + * @password: the password to use. * * Creates a new #GtkGisLayerSourcePostgis object. * * Returns: the newly created #GtkGisLayerSourcePostgis object. */ GtkGisLayerSourcePostgis -*gtk_gis_layer_source_postgis_new () +*gtk_gis_layer_source_postgis_new (gchar *host, + gint port, + gchar *username, + gchar *password) { GtkGisLayerSourcePostgis *gtk_gis_layer_source_postgis; + GtkGisLayerSourcePostgisPrivate *priv; gtk_gis_layer_source_postgis = GTK_GIS_LAYER_SOURCE_POSTGIS (g_object_new (gtk_gis_layer_source_postgis_get_type (), NULL)); + priv = GTK_GIS_LAYER_SOURCE_POSTGIS_GET_PRIVATE (gtk_gis_layer_source_postgis); + + priv->host = g_strdup (host == NULL ? "localhost" : host); + priv->port = (port == 0 ? 5432 : port); + priv->username = g_strdup (username == NULL ? "" : username); + priv->password = g_strdup (password == NULL ? "" : password); + return gtk_gis_layer_source_postgis; } diff --git a/src/layersourcepostgis.h b/src/layersourcepostgis.h index e479f94..a9bd32b 100644 --- a/src/layersourcepostgis.h +++ b/src/layersourcepostgis.h @@ -49,7 +49,10 @@ struct _GtkGisLayerSourcePostgisClass GType gtk_gis_layer_source_postgis_get_type (void) G_GNUC_CONST; -GtkGisLayerSourcePostgis *gtk_gis_layer_source_postgis_new (void); +GtkGisLayerSourcePostgis *gtk_gis_layer_source_postgis_new (gchar *host, + gint port, + gchar *username, + gchar *password); G_END_DECLS diff --git a/src/layersourceshp.c b/src/layersourceshp.c index 83537e5..aebc1db 100644 --- a/src/layersourceshp.c +++ b/src/layersourceshp.c @@ -20,11 +20,16 @@ #include #endif +#include +#include + #include "layersourceshp.h" static void gtk_gis_layer_source_shp_class_init (GtkGisLayerSourceShpClass *klass); static void gtk_gis_layer_source_shp_init (GtkGisLayerSourceShp *gtk_gis_layer_source_shp); +static OGRDataSourceH gtk_gis_layer_source_get_ogr_datasource (GtkGisLayerSource *source); + static void gtk_gis_layer_source_shp_set_property (GObject *object, guint property_id, const GValue *value, @@ -40,6 +45,9 @@ static void gtk_gis_layer_source_shp_get_property (GObject *object, typedef struct _GtkGisLayerSourceShpPrivate GtkGisLayerSourceShpPrivate; struct _GtkGisLayerSourceShpPrivate { + gchar *filename; + + OGRDataSourceH datasource; }; GType @@ -74,11 +82,15 @@ static void gtk_gis_layer_source_shp_class_init (GtkGisLayerSourceShpClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkGisLayerSourceClass *gtkgislayersource_class = GTK_GIS_LAYER_SOURCE_CLASS (klass); g_type_class_add_private (object_class, sizeof (GtkGisLayerSourceShpPrivate)); object_class->set_property = gtk_gis_layer_source_shp_set_property; object_class->get_property = gtk_gis_layer_source_shp_get_property; + + gtkgislayersource_class->fill_layer = gtk_gis_layer_source_shp_fill_layer; + gtkgislayersource_class->get_layer_geometry_type = gtk_gis_layer_source_shp_get_layer_geometry_type; } static void @@ -89,21 +101,133 @@ gtk_gis_layer_source_shp_init (GtkGisLayerSourceShp *gtk_gis_layer_source_shp) /** * gtk_gis_layer_source_shp_new: + * @filename: a file name. * * Creates a new #GtkGisLayerSourceShp object. * * Returns: the newly created #GtkGisLayerSourceShp object. */ GtkGisLayerSourceShp -*gtk_gis_layer_source_shp_new () +*gtk_gis_layer_source_shp_new (gchar *filename) { GtkGisLayerSourceShp *gtk_gis_layer_source_shp; gtk_gis_layer_source_shp = GTK_GIS_LAYER_SOURCE_SHP (g_object_new (gtk_gis_layer_source_shp_get_type (), NULL)); + GtkGisLayerSourceShpPrivate *priv = GTK_GIS_LAYER_SOURCE_SHP_GET_PRIVATE (gtk_gis_layer_source_shp); + + priv->filename = g_strdup (filename); + + /* Register all OGR drivers */ + OGRRegisterAll (); + + /* Open data source */ + priv->datasource = OGROpen (priv->filename, 0 /* bUpdate */, NULL); + return gtk_gis_layer_source_shp; } +/** + * gtk_gis_layer_source_shp_new: + * @source: + * + * Returns: the #GtkGisLayerSourceShp's file name. + */ +gchar +*gtk_gis_layer_get_filename (GtkGisLayerSourceShp *source) +{ + GtkGisLayerSourceShpPrivate *priv = GTK_GIS_LAYER_SOURCE_SHP_GET_PRIVATE (source); + + return g_strdup (priv->filename); +} + +/** + * gtk_gis_layer_source_shp_fill_layer: + * @source: + * @layer: + * + * Loads the #GtkGisLayerSource from the disk. + * + * Returns: FALSE on error. + */ +gboolean +gtk_gis_layer_source_shp_fill_layer (GtkGisLayerSource *source, + GtkGisLayer *layer) +{ + gboolean ret = TRUE; + + GtkGisLayerSourceShpPrivate *priv = GTK_GIS_LAYER_SOURCE_SHP_GET_PRIVATE (gtk_gis_layer_source); + + if (priv->datasource == NULL) + { + /* TO DO */ + ret = FALSE; + } + + return ret; +} + +/** + * gtk_gis_layer_source_shp_get_layer_geometry_type: + * @source: + * @name: + * + * Returns: a #GtkGisLayerGeometryType or -1 on error. + */ +GtkGisLayerGeometryType +gtk_gis_layer_source_shp_get_layer_geometry_type (GtkGisLayerSource *source, + gchar *name) +{ + GtkGisLayerGeometryType type = -1; + gint numLayers; + gint i; + + OGRLayerH layer; + OGRFeatureDefnH layerDefn; + + GtkGisLayerSourceShpPrivate *priv = GTK_GIS_LAYER_SOURCE_SHP_GET_PRIVATE (gtk_gis_layer_source); + + numLayers = OGR_DS_GetLayerCount (priv->datasource); + for (i = 0; i < numLayers; i++) + { + layer = OGR_DS_GetLayer (priv->datasource, i); + layerDefn = OGR_L_GetLayerDefn (layer); + + if (strcmp (name, OGR_FD_GetName(layerDefn)) == 0) + { + OGRFeatureH feature; + + feature = OGR_L_GetNextFeature (layer); + + if (feature != NULL) + { + OGRGeometryH poGeometry; + + poGeometry = OGR_F_GetGeometryRef (feature); + if (poGeometry != NULL + && wkbFlatten(OGR_G_GetGeometryType(poGeometry)) == wkbPoint) + { + type = LAYER_GEOMETRY_TYPE_POINT; + } + else if (poGeometry != NULL + && wkbFlatten(OGR_G_GetGeometryType(poGeometry)) == wkbLineString) + { + type = LAYER_GEOMETRY_TYPE_LINE; + } + else if (poGeometry != NULL + && wkbFlatten(OGR_G_GetGeometryType(poGeometry)) == wkbPolygon) + { + type = LAYER_GEOMETRY_TYPE_POLYGON; + } + } + + break; + } + } + + return type; +} + static void gtk_gis_layer_source_shp_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { diff --git a/src/layersourceshp.h b/src/layersourceshp.h index 0b46a63..19fed23 100644 --- a/src/layersourceshp.h +++ b/src/layersourceshp.h @@ -49,7 +49,9 @@ struct _GtkGisLayerSourceShpClass GType gtk_gis_layer_source_shp_get_type (void) G_GNUC_CONST; -GtkGisLayerSourceShp *gtk_gis_layer_source_shp_new (void); +GtkGisLayerSourceShp *gtk_gis_layer_source_shp_new (gchar *filename); + +gchar *gtk_gis_layer_get_filename (GtkGisLayerSourceShp *source); G_END_DECLS