]> saetta.ns0.it Git - libgtkgis/commitdiff
Continued base classes.
authorAndrea Zagli <azagli@libero.it>
Sun, 21 Jun 2009 17:19:58 +0000 (19:19 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 21 Jun 2009 17:19:58 +0000 (19:19 +0200)
Added gtkgis.dtd.

21 files changed:
Makefile.am
configure.ac
data/Makefile.am [new file with mode: 0644]
data/gtkgis.dtd [new file with mode: 0644]
src/Makefile.am
src/geometryline.c [new file with mode: 0644]
src/geometryline.h [new file with mode: 0644]
src/geometrypoint.c [new file with mode: 0644]
src/geometrypoint.h [new file with mode: 0644]
src/geometrypolygon.c [new file with mode: 0644]
src/geometrypolygon.h [new file with mode: 0644]
src/geometryraster.c [new file with mode: 0644]
src/geometryraster.h [new file with mode: 0644]
src/layer.c
src/layer.h
src/layersource.c
src/layersource.h
src/layersourcepostgis.c
src/layersourcepostgis.h
src/layersourceshp.c
src/layersourceshp.h

index e4af89905ead6b4881fc111adff6e00bd295b387..e9e5101ad4f2622ad9cf7b53306f3fbfa253091e 100644 (file)
@@ -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
 
index 29dc4a6019ee7404c41f78ee03e3cab0d1366608..c050dc591e49fc0b5b1ef20b5ab4f32fc4ce7637 100644 (file)
@@ -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 (file)
index 0000000..ffc0d6c
--- /dev/null
@@ -0,0 +1,2 @@
+EXTRA_DIST = \
+             gtkgis.dtd
diff --git a/data/gtkgis.dtd b/data/gtkgis.dtd
new file mode 100644 (file)
index 0000000..43ad2bc
--- /dev/null
@@ -0,0 +1,21 @@
+<!ELEMENT gtkgis (layer*)>
+
+<!ELEMENT layer (source)>
+<!ATTLIST layer
+  name CDATA #REQUIRED
+>
+
+<!ELEMENT source (shape | postgis)>
+
+<!ELEMENT shape>
+<!ATTLIST
+  filename CDATA #REQUIRED
+>
+
+<!ELEMENT postgis>
+<!ATTLIST
+  host CDATA #REQUIRED
+  port CDATA #REQUIRED
+  username CDATA #REQUIRED
+  password CDATA #REQUIRED
+>
index 753e6877709aa2a0604fa5098a94229165765ceb..2cd0b816cd84f6ebf64a3cd9517edc931620ca8f 100644 (file)
@@ -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 (file)
index 0000000..3a5b6b1
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2009 Andrea Zagli <azagli@libero.it>
+ *
+ * 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 <cairo.h>
+
+#include <ogr_api.h>
+#include <ogr_core.h>
+
+#ifdef HAVE_CONFIG_H
+       #include <config.h>
+#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",
+                                                                 &gtk_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 (file)
index 0000000..0383fb2
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2009 Andrea Zagli <azagli@libero.it>
+ *
+ * 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 (file)
index 0000000..eb3519f
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2009 Andrea Zagli <azagli@libero.it>
+ *
+ * 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 <cairo.h>
+
+#include <ogr_api.h>
+#include <ogr_core.h>
+
+#ifdef HAVE_CONFIG_H
+       #include <config.h>
+#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",
+                                                                 &gtk_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 (file)
index 0000000..15eec16
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2009 Andrea Zagli <azagli@libero.it>
+ *
+ * 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 (file)
index 0000000..bfb4af9
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2009 Andrea Zagli <azagli@libero.it>
+ *
+ * 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 <cairo.h>
+
+#include <ogr_api.h>
+#include <ogr_core.h>
+
+#ifdef HAVE_CONFIG_H
+       #include <config.h>
+#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",
+                                                                 &gtk_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 (file)
index 0000000..2b740e9
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2009 Andrea Zagli <azagli@libero.it>
+ *
+ * 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 (file)
index 0000000..4fe3800
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2009 Andrea Zagli <azagli@libero.it>
+ *
+ * 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 <cairo.h>
+
+#include <ogr_api.h>
+#include <ogr_core.h>
+
+#ifdef HAVE_CONFIG_H
+       #include <config.h>
+#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",
+                                                                 &gtk_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 (file)
index 0000000..e8ac4e9
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2009 Andrea Zagli <azagli@libero.it>
+ *
+ * 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__ */
index 446276d73248153af6fa6c74502fc8d0af6df6b2..bf15d643acf06720b3ccea03088c867c5b48fd2d 100644 (file)
@@ -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
index e55ed7323c3c3a69ea288e1dbfcc721960a55522..407950f5dcc59dc1081cf70cc0818ac2dc2a9061 100644 (file)
@@ -23,6 +23,8 @@
 #include <glib.h>
 #include <glib-object.h>
 
+#include <goocanvas.h>
+
 #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
 
index b9edfcda18821a939d4d93b96538ae48d982af12..9d2649c52cfad3d9ba74deafd78dfa7b79dd7146 100644 (file)
@@ -20,6 +20,9 @@
        #include <config.h>
 #endif
 
+#include <ogr_api.h>
+#include <ogr_core.h>
+
 #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)
 {
index 2e8cb1163f78e8ed8d71d5a50e5f4a8fe26eef9f..7bef22d674adb3fb4d2044bda622b92b927433e1 100644 (file)
@@ -23,6 +23,8 @@
 #include <glib.h>
 #include <glib-object.h>
 
+#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
 
index 46e3539b6aabf0e788df63d5f3a2f893900562f9..6ec132665cd3e130674ba5f828858ed7c067094f 100644 (file)
@@ -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;
 }
 
index e479f94e47d2e5eb174997448d968167d2592fc0..a9bd32b4a015fbf69fb5a7f906d486a194518637 100644 (file)
@@ -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
index 83537e5335bb2d2968ae272b027e43bc77f3d0c7..aebc1db3b8d01d597c59508973de0f7503efc1c7 100644 (file)
        #include <config.h>
 #endif
 
+#include <ogr_api.h>
+#include <ogr_core.h>
+
 #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)
 {
index 0b46a63ce93a3c5374568ca45bc46da8fdc27edb..19fed238e8955133f4893298c2e4ff3d463f5a7d 100644 (file)
@@ -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