Implemented geometry classes.
Moved LayerSourceShp::get_geometry_type and LayerSourceShp::get_geometries funtions to LayerSource.
src/.libs/
stamp-h1
tests/.deps
+tests/.libs
tests/from_xml
# temporarily
GType gtk_gis_geometry_get_type (void) G_GNUC_CONST;
+typedef struct
+ {
+ gdouble x;
+ gdouble y;
+ } GtkGisPoint;
+
+
gboolean gtk_gis_geometry_get_editable (GtkGisGeometry *geometry);
void gtk_gis_geometry_set_editable (GtkGisGeometry *geometry, gboolean editable);
GPtrArray *points;
};
-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;
-}
+G_DEFINE_TYPE (GtkGisGeometryLine, gtk_gis_geometry_line, TYPE_GTK_GIS_GEOMETRY)
static void
gtk_gis_geometry_line_class_init (GtkGisGeometryLineClass *klass)
*
* Returns: the newly created #GtkGisGeometryLine object.
*/
-GtkGisGeometryLine
+GtkGisGeometry
*gtk_gis_geometry_line_new ()
{
- GtkGisGeometryLine *gtk_gis_geometry_line;
+ GtkGisGeometry *gtk_gis_geometry_line;
- gtk_gis_geometry_line = GTK_GIS_GEOMETRY_LINE (g_object_new (gtk_gis_geometry_line_get_type (), NULL));
+ gtk_gis_geometry_line = g_object_new (gtk_gis_geometry_line_get_type (), NULL);
return gtk_gis_geometry_line;
}
*
* Returns: the newly created #GtkGisGeometryLine object.
*/
-GtkGisGeometryLine
+GtkGisGeometry
*gtk_gis_geometry_line_new_from_array (GPtrArray *points)
{
- GtkGisGeometryLine *gtk_gis_geometry_line;
+ GtkGisGeometry *line;
GtkGisGeometryLinePrivate *priv;
- gtk_gis_geometry_line = gtk_gis_geometry_line_new ();
+ line = gtk_gis_geometry_line_new ();
- priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (gtk_gis_geometry_line);
+ priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (GTK_GIS_GEOMETRY_LINE (line));
priv->points = points;
- return gtk_gis_geometry_line;
+ return line;
}
/**
- * gtk_gis_geomtry_line_add_point:
+ * gtk_gis_geometry_line_add_point:
* @line:
* @point:
*/
void
-gtk_gis_geomtry_line_add_point (GtkGisGeometryLine *line, GtkGisGeometryPoint *point)
+gtk_gis_geometry_line_add_point (GtkGisGeometryLine *line, GtkGisPoint point)
{
GtkGisGeometryLinePrivate *priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (line);
- g_ptr_array_add (priv->points, point);
+ GtkGisPoint *gpoint;
+
+ gpoint = g_malloc0 (sizeof (GtkGisPoint));
+
+ gpoint->x = point.x;
+ gpoint->y = point.y;
+
+ g_ptr_array_add (priv->points, gpoint);
}
/**
*
*/
void
-gtk_gis_geomtry_line_add_point_from_coordinates (GtkGisGeometryLine *line,
- gdouble x, gdouble y)
+gtk_gis_geometry_line_add_point_from_coordinates (GtkGisGeometryLine *line,
+ gdouble x, gdouble y)
{
- GtkGisGeometryPoint *point;
+ GtkGisPoint gpoint;
- point = gtk_gis_geometry_point_new (x, y);
+ gpoint.x = x;
+ gpoint.y = y;
- gtk_gis_geometry_line_add_point (line, point);
+ gtk_gis_geometry_line_add_point (line, gpoint);
}
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);
+ GtkGisGeometryLine *line = GTK_GIS_GEOMETRY_LINE (object);
- GtkGisGeometryLinePrivate *priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (gtk_gis_geometry_line);
+ GtkGisGeometryLinePrivate *priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (line);
switch (property_id)
{
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);
+ GtkGisGeometryLine *line = GTK_GIS_GEOMETRY_LINE (object);
- GtkGisGeometryLinePrivate *priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (gtk_gis_geometry_line);
+ GtkGisGeometryLinePrivate *priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (line);
switch (property_id)
{
GType gtk_gis_geometry_line_get_type (void) G_GNUC_CONST;
-GtkGisGeometryLine *gtk_gis_geometry_line_new (void);
+GtkGisGeometry *gtk_gis_geometry_line_new (void);
-GtkGisGeometryLine *gtk_gis_geometry_line_new_from_array (GPtrArray *points);
+GtkGisGeometry *gtk_gis_geometry_line_new_from_array (GPtrArray *points);
-void gtk_gis_geomtry_line_add_point (GtkGisGeometryLine *line, GtkGisGeometryPoint *point);
-void gtk_gis_geomtry_line_add_point_from_coordinates (GtkGisGeometryLine *line,
- gdouble x, gdouble y);
+void gtk_gis_geometry_line_add_point (GtkGisGeometryLine *line, GtkGisPoint point);
+void gtk_gis_geometry_line_add_point_from_coordinates (GtkGisGeometryLine *line,
+ gdouble x, gdouble y);
typedef struct _GtkGisGeometryPointPrivate GtkGisGeometryPointPrivate;
struct _GtkGisGeometryPointPrivate
{
- gdouble x;
- gdouble y;
+ GtkGisPoint point;
};
GType
NULL
};
- gtk_gis_geometry_point_type = g_type_register_static (G_TYPE_OBJECT, "GtkGisGeometryPoint",
+ gtk_gis_geometry_point_type = g_type_register_static (TYPE_GTK_GIS_GEOMETRY, "GtkGisGeometryPoint",
>k_gis_geometry_point_info, 0);
}
/**
* gtk_gis_geometry_point_new:
- * @x:
- * @y:
+ * @point:
*
* Creates a new #GtkGisGeometryPoint object.
*
* Returns: the newly created #GtkGisGeometryPoint object.
*/
-GtkGisGeometryPoint
-*gtk_gis_geometry_point_new (gdouble x, gdouble y)
+GtkGisGeometry
+*gtk_gis_geometry_point_new (GtkGisPoint point)
{
- GtkGisGeometryPoint *gtk_gis_geometry_point;
+ GtkGisGeometry *gpoint;
GtkGisGeometryPointPrivate *priv;
- gtk_gis_geometry_point = GTK_GIS_GEOMETRY_POINT (g_object_new (gtk_gis_geometry_point_get_type (), NULL));
+ gpoint = g_object_new (gtk_gis_geometry_point_get_type (), NULL);
- priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (gtk_gis_geometry_point);
+ priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (GTK_GIS_GEOMETRY_POINT (gpoint));
- priv->x = x;
- priv->y = y;
+ priv->point.x = point.x;
+ priv->point.y = point.y;
- return gtk_gis_geometry_point;
+ return gpoint;
}
+/**
+ * gtk_gis_geometry_get_point:
+ * @point:
+ *
+ * Returns:
+ */
+GtkGisPoint
+*gtk_gis_geometry_get_point (GtkGisGeometryPoint *point)
+{
+ GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (point);
+
+ GtkGisPoint *gpoint;
+
+ gpoint = g_malloc0 (sizeof (GtkGisPoint));
+
+ gpoint->x = priv->point.x;
+ gpoint->y = priv->point.y;
+
+ return gpoint;
+}
+
+/**
+ * gtk_gis_geometry_point_get_x:
+ * @point:
+ *
+ */
gdouble
-gtk_gis_geometry_get_x (GtkGisGeometryPoint *point)
+gtk_gis_geometry_point_get_x (GtkGisGeometryPoint *point)
{
GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (point);
- return priv->x;
+ return priv->point.x;
}
+/**
+ * gtk_gis_geometry_point_get_y:
+ * @point:
+ *
+ */
gdouble
-gtk_gis_geometry_get_y (GtkGisGeometryPoint *point)
+gtk_gis_geometry_point_get_y (GtkGisGeometryPoint *point)
{
GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (point);
- return priv->y;
+ return priv->point.y;
}
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);
+ GtkGisGeometryPoint *point = GTK_GIS_GEOMETRY_POINT (object);
- GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (gtk_gis_geometry_point);
+ GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (point);
switch (property_id)
{
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);
+ GtkGisGeometryPoint *point = GTK_GIS_GEOMETRY_POINT (object);
- GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (gtk_gis_geometry_point);
+ GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (point);
switch (property_id)
{
GType gtk_gis_geometry_point_get_type (void) G_GNUC_CONST;
-GtkGisGeometryPoint *gtk_gis_geometry_point_new (gdouble x, gdouble y);
+GtkGisGeometry *gtk_gis_geometry_point_new (GtkGisPoint point);
-gdouble gtk_gis_geometry_get_x (GtkGisGeometryPoint *point);
-gdouble gtk_gis_geometry_get_y (GtkGisGeometryPoint *point);
+GtkGisPoint *gtk_gis_geometry_get_point (GtkGisGeometryPoint *point);
+
+gdouble gtk_gis_geometry_point_get_x (GtkGisGeometryPoint *point);
+gdouble gtk_gis_geometry_point_get_y (GtkGisGeometryPoint *point);
G_END_DECLS
typedef struct _GtkGisGeometryPolygonPrivate GtkGisGeometryPolygonPrivate;
struct _GtkGisGeometryPolygonPrivate
{
+ GList *lines;
};
-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;
-}
+G_DEFINE_TYPE (GtkGisGeometryPolygon, gtk_gis_geometry_polygon, TYPE_GTK_GIS_GEOMETRY)
static void
gtk_gis_geometry_polygon_class_init (GtkGisGeometryPolygonClass *klass)
*
* Returns: the newly created #GtkGisGeometryPolygon object.
*/
-GtkGisGeometryPolygon
+GtkGisGeometry
*gtk_gis_geometry_polygon_new ()
{
- GtkGisGeometryPolygon *gtk_gis_geometry_polygon;
+ GtkGisGeometry *polygon;
+
+ polygon = g_object_new (gtk_gis_geometry_polygon_get_type (), NULL);
+
+ return polygon;
+}
+
+/**
+ * gtk_gis_geometry_polygon_new_from_line:
+ * @line: a #GtkGisGeometryLine object
+ *
+ * Creates a new #GtkGisGeometryPolygon object.
+ *
+ * Returns: the newly created #GtkGisGeometryPolygon object.
+ */
+GtkGisGeometry
+*gtk_gis_geometry_polygon_new_from_line (GtkGisGeometryLine *line)
+{
+ GtkGisGeometry *polygon;
+
+ polygon = gtk_gis_geometry_polygon_new ();
- gtk_gis_geometry_polygon = GTK_GIS_GEOMETRY_POLYGON (g_object_new (gtk_gis_geometry_polygon_get_type (), NULL));
+ gtk_gis_geometry_polygon_add_line (GTK_GIS_GEOMETRY_POLYGON (polygon), line);
- return gtk_gis_geometry_polygon;
+ return polygon;
}
/**
*
* Returns: the newly created #GtkGisGeometryPolygon object.
*/
-GtkGisGeometryPolygon
+GtkGisGeometry
*gtk_gis_geometry_polygon_new_from_array (GPtrArray *points)
{
- GtkGisGeometryPolygon *gtk_gis_geometry_polygon;
+ GtkGisGeometry *polygon;
+ GtkGisGeometry *line;
- gtk_gis_geometry_polygon = gtk_gis_geometry_line_new_from_array (points);
+ line = gtk_gis_geometry_line_new_from_array (points);
- return gtk_gis_geometry_polygon;
+ gtk_gis_geometry_polygon_add_line (GTK_GIS_GEOMETRY_POLYGON (polygon), GTK_GIS_GEOMETRY_LINE (line));
+
+ return polygon;
+}
+
+/**
+ * gtk_gis_geometry_polygon_add_line:
+ * @polygon:
+ * @line:
+ *
+ */
+void
+gtk_gis_geometry_polygon_add_line (GtkGisGeometryPolygon *polygon,
+ GtkGisGeometryLine *line)
+{
+ GtkGisGeometryPolygonPrivate *priv = GTK_GIS_GEOMETRY_POLYGON_GET_PRIVATE (polygon);
+
+ priv->lines = g_list_append (priv->lines, line);
+}
+
+/**
+ * gtk_gis_geometry_polygon_remove_line:
+ * @polygon:
+ * @line:
+ *
+ */
+void
+gtk_gis_geometry_polygon_remove_line (GtkGisGeometryPolygon *polygon,
+ GtkGisGeometryLine *line)
+{
+ GtkGisGeometryPolygonPrivate *priv = GTK_GIS_GEOMETRY_POLYGON_GET_PRIVATE (polygon);
+
+ priv->lines = g_list_remove (priv->lines, line);
}
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);
+ GtkGisGeometryPolygon *polygon = GTK_GIS_GEOMETRY_POLYGON (object);
- GtkGisGeometryPolygonPrivate *priv = GTK_GIS_GEOMETRY_POLYGON_GET_PRIVATE (gtk_gis_geometry_polygon);
+ GtkGisGeometryPolygonPrivate *priv = GTK_GIS_GEOMETRY_POLYGON_GET_PRIVATE (polygon);
switch (property_id)
{
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);
+ GtkGisGeometryPolygon *polygon = GTK_GIS_GEOMETRY_POLYGON (object);
- GtkGisGeometryPolygonPrivate *priv = GTK_GIS_GEOMETRY_POLYGON_GET_PRIVATE (gtk_gis_geometry_polygon);
+ GtkGisGeometryPolygonPrivate *priv = GTK_GIS_GEOMETRY_POLYGON_GET_PRIVATE (polygon);
switch (property_id)
{
#ifndef __GTK_GIS_GEOMETRY_POLYGON_H__
#define __GTK_GIS_GEOMETRY_POLYGON_H__
+#include "geometry.h"
#include "geometryline.h"
G_BEGIN_DECLS
struct _GtkGisGeometryPolygon
{
- GtkGisGeometryLine parent;
+ GtkGisGeometry parent;
};
struct _GtkGisGeometryPolygonClass
{
- GtkGisGeometryLineClass parent_class;
+ GtkGisGeometryClass parent_class;
};
GType gtk_gis_geometry_polygon_get_type (void) G_GNUC_CONST;
-GtkGisGeometryPolygon *gtk_gis_geometry_polygon_new (void);
+GtkGisGeometry *gtk_gis_geometry_polygon_new (void);
-GtkGisGeometryPolygon *gtk_gis_geometry_polygon_new_from_array (GPtrArray *points);
+GtkGisGeometry *gtk_gis_geometry_polygon_new_from_line (GtkGisGeometryLine *line);
+GtkGisGeometry *gtk_gis_geometry_polygon_new_from_array (GPtrArray *points);
+
+void gtk_gis_geometry_polygon_add_line (GtkGisGeometryPolygon *polygon, GtkGisGeometryLine *line);
+void gtk_gis_geometry_polygon_remove_line (GtkGisGeometryPolygon *polygon, GtkGisGeometryLine *line);
G_END_DECLS
NULL
};
- gtk_gis_geometry_raster_type = g_type_register_static (G_TYPE_OBJECT, "GtkGisGeometryRaster",
+ gtk_gis_geometry_raster_type = g_type_register_static (TYPE_GTK_GIS_GEOMETRY, "GtkGisGeometryRaster",
>k_gis_geometry_raster_info, 0);
}
*
* Returns: the newly created #GtkGisGeometryRaster object.
*/
-GtkGisGeometryRaster
+GtkGisGeometry
*gtk_gis_geometry_raster_new ()
{
- GtkGisGeometryRaster *gtk_gis_geometry_raster;
+ GtkGisGeometry *raster;
- gtk_gis_geometry_raster = GTK_GIS_GEOMETRY_RASTER (g_object_new (gtk_gis_geometry_raster_get_type (), NULL));
+ raster = g_object_new (gtk_gis_geometry_raster_get_type (), NULL);
- return gtk_gis_geometry_raster;
+ return 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);
+ GtkGisGeometryRaster *raster = GTK_GIS_GEOMETRY_RASTER (object);
- GtkGisGeometryRasterPrivate *priv = GTK_GIS_GEOMETRY_RASTER_GET_PRIVATE (gtk_gis_geometry_raster);
+ GtkGisGeometryRasterPrivate *priv = GTK_GIS_GEOMETRY_RASTER_GET_PRIVATE (raster);
switch (property_id)
{
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);
+ GtkGisGeometryRaster *raster = GTK_GIS_GEOMETRY_RASTER (object);
- GtkGisGeometryRasterPrivate *priv = GTK_GIS_GEOMETRY_RASTER_GET_PRIVATE (gtk_gis_geometry_raster);
+ GtkGisGeometryRasterPrivate *priv = GTK_GIS_GEOMETRY_RASTER_GET_PRIVATE (raster);
switch (property_id)
{
GType gtk_gis_geometry_raster_get_type (void) G_GNUC_CONST;
-GtkGisGeometryRaster *gtk_gis_geometry_raster_new (void);
+GtkGisGeometry *gtk_gis_geometry_raster_new (void);
G_END_DECLS
#endif
#include "gtkgis.h"
+#include "layer.h"
+#include "layersource.h"
+#include "layersourceshp.h"
+#include "layersourcepostgis.h"
static void gtk_gis_class_init (GtkGisClass *klass);
static void gtk_gis_init (GtkGis *gtk_gis);
+static void gtk_gis_add (GtkContainer *container,
+ GtkWidget *widget);
+
static void gtk_gis_set_property (GObject *object,
guint property_id,
const GValue *value,
typedef struct _GtkGisPrivate GtkGisPrivate;
struct _GtkGisPrivate
{
+ GtkWidget *scroll_win;
+
GtkWidget *canvas;
GooCanvasItem *canvas_root;
GList *layer_groups;
GList *layers;
- };
-GType
-gtk_gis_get_type (void)
-{
- static GType gtk_gis_type = 0;
-
- if (!gtk_gis_type)
- {
- static const GTypeInfo gtk_gis_info =
- {
- sizeof (GtkGisClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) gtk_gis_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GtkGis),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gtk_gis_init,
- NULL
- };
-
- gtk_gis_type = g_type_register_static (G_TYPE_OBJECT, "GtkGis",
- >k_gis_info, 0);
- }
+ GtkGisLayerExtent extent;
+ };
- return gtk_gis_type;
-}
+G_DEFINE_TYPE (GtkGis, gtk_gis, GTK_TYPE_BIN)
static void
gtk_gis_class_init (GtkGisClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = (GtkWidgetClass*) klass;
+ GtkContainerClass *container_class = (GtkContainerClass*) klass;
g_type_class_add_private (object_class, sizeof (GtkGisPrivate));
object_class->set_property = gtk_gis_set_property;
object_class->get_property = gtk_gis_get_property;
+
+ container_class->add = gtk_gis_add;
}
static void
gtk_gis_init (GtkGis *gtk_gis)
{
GtkGisPrivate *priv = GTK_GIS_GET_PRIVATE (gtk_gis);
+
+ priv->scroll_win = gtk_scrolled_window_new (NULL, NULL);
+ gtk_container_add (GTK_CONTAINER (gtk_gis), priv->scroll_win);
+
+ priv->canvas = goo_canvas_new ();
+ gtk_container_add (GTK_CONTAINER (priv->scroll_win), priv->canvas);
+
+ priv->canvas_root = goo_canvas_get_root_item (GOO_CANVAS (priv->canvas));
}
/**
*
* Returns: the newly created #GtkGis object.
*/
-GtkGis
+GtkWidget
*gtk_gis_new ()
{
- GtkGis *gtk_gis;
+ GtkWidget *gtk_gis;
+ GtkGisPrivate *priv;
- gtk_gis = GTK_GIS (g_object_new (gtk_gis_get_type (), NULL));
+ gtk_gis = g_object_new (gtk_gis_get_type (), NULL);
+
+ priv = GTK_GIS_GET_PRIVATE (GTK_GIS (gtk_gis));
return gtk_gis;
}
*
* Returns: the newly created #GtkGis object.
*/
-GtkGis
+GtkWidget
*gtk_gis_new_from_xml (xmlDoc *xdoc)
{
- GtkGis *gtkgis = NULL;
+ GtkWidget *gtkgis = NULL;
xmlNode *cur;
cur = xmlDocGetRootElement (xdoc);
gtkgis = gtk_gis_new ();
- priv = GTK_GIS_GET_PRIVATE (gtkgis);
+ priv = GTK_GIS_GET_PRIVATE (GTK_GIS (gtkgis));
cur = cur->children;
while (cur != NULL)
xml_layer = cur;
layer_name = xmlGetProp (cur, (const xmlChar *)"name");
- if (layer_name != NULL)
+ if (layer_name == NULL)
{
/* TO DO */
/* get layer source name */
}
cur = cur->children;
- if (cur != NULL
- && cur->type == XML_ELEMENT_NODE
- && xmlStrcmp (cur->name, "source") == 0)
+ while (cur != NULL)
{
- xmlNode *xml_source;
-
- xml_source = cur;
-
- if (cur != NULL
- && cur->type == XML_ELEMENT_NODE
- && (xmlStrcmp (cur->name, "shape") == 0
- || xmlStrcmp (cur->name, "postgis") == 0))
+ if (cur->type == XML_ELEMENT_NODE
+ && xmlStrcmp (cur->name, "source") == 0)
{
- xmlNode *xml_source_spec;
- GtkGisLayer *layer = NULL;
- GtkGisLayerSource *layer_source = NULL;
+ xmlNode *xml_source;
- xml_source_spec = cur;
+ xml_source = cur;
- if (xmlStrcmp (cur->name, "shape") == 0)
+ cur = cur->children;
+ while (cur != NULL)
{
- gchar *filename;
-
- filename = xmlGetProp (cur, (const xmlChar *)"filename");
- if (filename != NULL)
+ if (cur->type == XML_ELEMENT_NODE
+ && (xmlStrcmp (cur->name, "shape") == 0
+ || xmlStrcmp (cur->name, "postgis") == 0))
{
- layer_source = GTK_GIS_LAYER_SOURCE (gtk_gis_layer_source_shp_new (filename));
+ xmlNode *xml_source_spec;
+ GtkGisLayer *layer = NULL;
+ GtkGisLayerSource *layer_source = NULL;
+
+ xml_source_spec = cur;
+
+ if (xmlStrcmp (cur->name, "shape") == 0)
+ {
+ gchar *filename;
+
+ filename = xmlGetProp (cur, (const xmlChar *)"filename");
+ if (filename != NULL)
+ {
+ layer_source = gtk_gis_layer_source_shp_new ((const gchar *)filename);
+ }
+ }
+ else if (xmlStrcmp (cur->name, "postgis") == 0)
+ {
+ layer_source = gtk_gis_layer_source_postgis_new (xmlGetProp (cur, (const xmlChar *)"host"),
+ atol (xmlGetProp (cur, (const xmlChar *)"port")),
+ xmlGetProp (cur, (const xmlChar *)"username"),
+ xmlGetProp (cur, (const xmlChar *)"password"));
+ }
+
+ if (layer_source != NULL)
+ {
+ layer = gtk_gis_layer_new_from_source (layer_source, layer_name);
+ gtk_gis_add_layer (GTK_GIS (gtkgis), layer);
+ }
+
+ cur = xml_source_spec;
}
+ cur = cur->next;
}
- else if (xmlStrcmp (cur->name, "postgis") == 0)
- {
- /* TO DO */
- }
-
- if (layer_source != NULL)
- {
- layer = gtk_gis_layer_new_from_source (layer_source, layer_name);
- gtk_gis_add_layer (gtkgis, layer);
- }
-
- cur = xml_source_spec;
+ cur = xml_source;
}
-
- cur = xml_source;
+ cur = cur->next;
}
-
cur = xml_layer;
}
-
cur = cur->next;
}
}
*
* Returns: the newly created #GtkGis object.
*/
-GtkGis
+GtkWidget
*gtk_gis_new_from_file (const gchar *filename)
{
- GtkGis *gtkgis = NULL;
+ GtkWidget *gtkgis = NULL;
xmlDoc *xdoc = xmlParseFile (filename);
if (xdoc != NULL)
void
gtk_gis_add_layer (GtkGis *gtkgis, GtkGisLayer *layer)
{
- GtkGisPrivate *priv = GTK_GIS_GET_PRIVATE (gtkgis);
+ GtkGisPrivate *priv;
+ GtkGisLayerExtent extent;
+
+ priv = GTK_GIS_GET_PRIVATE (gtkgis);
priv->layers = g_list_append (priv->layers, layer);
+
+ extent = gtk_gis_layer_get_extent (layer);
+
+ if (extent.min_x < priv->extent.min_x)
+ {
+ priv->extent.min_x = extent.min_x;
+ }
+ if (extent.min_y < priv->extent.min_y)
+ {
+ priv->extent.min_y = extent.min_y;
+ }
+ if (extent.max_x > priv->extent.max_x)
+ {
+ priv->extent.max_x = extent.max_x;
+ }
+ if (extent.max_y > priv->extent.max_y)
+ {
+ priv->extent.max_y = extent.max_y;
+ }
+
+ goo_canvas_set_bounds (GOO_CANVAS (priv->canvas),
+ priv->extent.min_x,
+ priv->extent.min_y,
+ priv->extent.max_x,
+ priv->extent.max_y);
}
/**
priv->layers = g_list_remove (priv->layers, layer);
}
+static void
+gtk_gis_add (GtkContainer *container,
+ GtkWidget *child)
+{
+ GtkGis *gtkgis;
+ GtkBin *bin;
+
+ bin = GTK_BIN (container);
+ g_return_if_fail (bin->child == NULL);
+
+ gtkgis = GTK_GIS (container);
+
+ bin->child = child;
+ gtk_widget_set_parent (child, GTK_WIDGET (bin));
+}
+
static void
gtk_gis_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
#ifndef __GTK_GIS_H__
#define __GTK_GIS_H__
-#include <gtk/gtkwidget.h>
+#include <gtk/gtk.h>
#include <libxml/tree.h>
#include "layersgroup.h"
struct _GtkGis
{
- GtkWidget parent;
+ GtkBin parent;
};
struct _GtkGisClass
{
- GtkWidgetClass parent_class;
+ GtkBinClass parent_class;
};
GType gtk_gis_get_type (void) G_GNUC_CONST;
-GtkGis *gtk_gis_new (void);
+GtkWidget *gtk_gis_new (void);
-GtkGis *gtk_gis_new_from_xml (xmlDoc *xdoc);
-GtkGis *gtk_gis_new_from_file (const gchar *filename);
+GtkWidget *gtk_gis_new_from_xml (xmlDoc *xdoc);
+GtkWidget *gtk_gis_new_from_file (const gchar *filename);
void *gtk_gis_save_to_xml (GtkGis *gtkgis, const gchar *filename);
layer = gtk_gis_layer_new (source, name, type);
- gtk_gis_layer_source_fill_layer (source, layer);
+ gtk_gis_layer_fill_from_source (layer);
return layer;
}
{
GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
- gtk_gis_layer_source_fill_layer (priv->source, layer);
+ priv->geometries = gtk_gis_layer_source_get_geometries (priv->source, priv->name);
}
/**
priv->geometries = g_list_remove (priv->geometries, geometry);
}
+/**
+ * gtk_gis_layer_get_extent:
+ * @layer:
+ *
+ */
+GtkGisLayerExtent
+gtk_gis_layer_get_extent (GtkGisLayer *layer)
+{
+ GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+
+ GtkGisLayerExtent extent;
+
+ extent = gtk_gis_layer_source_get_layer_extent (priv->source, priv->name);
+
+ return extent;
+}
+
/**
* gtk_gis_layer_get_editable:
* @layer:
void gtk_gis_layer_remove_geometry (GtkGisLayer *layer,
GtkGisGeometry *geometry);
+GtkGisLayerExtent gtk_gis_layer_get_extent (GtkGisLayer *layer);
+
gboolean gtk_gis_layer_get_editable (GtkGisLayer *layer);
void gtk_gis_layer_set_editable (GtkGisLayer *layer,
gboolean editable);
GtkGisLayersGroup
*gtk_gis_layers_group_new (const gchar *name)
{
- GtkGisLayersGroup *gtk_gis_layers_group;
+ GtkGisLayersGroup *group;
GtkGisLayersGroupPrivate *priv;
- gtk_gis_layers_group = GTK_GIS_LAYERS_GROUP (g_object_new (gtk_gis_layers_group_get_type (), NULL));
+ group = GTK_GIS_LAYERS_GROUP (g_object_new (gtk_gis_layers_group_get_type (), NULL));
- priv = GTK_GIS_LAYERS_GROUP_GET_PRIVATE (gtk_gis_layers_group);
+ priv = GTK_GIS_LAYERS_GROUP_GET_PRIVATE (group);
priv->name = g_strdup (name);
- return gtk_gis_layers_group;
+ return group;
}
/**
#include <ogr_core.h>
#include "layersource.h"
+#include "geometryline.h"
+#include "geometrypoint.h"
+#include "geometrypolygon.h"
static void gtk_gis_layer_source_class_init (GtkGisLayerSourceClass *klass);
static void gtk_gis_layer_source_init (GtkGisLayerSource *gtk_gis_layer_source);
+static void
+gtk_gis_layer_source_set_ogr_datasource (GtkGisLayerSource *source,
+ OGRDataSourceH datasource);
+
static void gtk_gis_layer_source_set_property (GObject *object,
guint property_id,
const GValue *value,
OGRDataSourceH datasource;
};
-GType
-gtk_gis_layer_source_get_type (void)
-{
- static GType gtk_gis_layer_source_type = 0;
-
- if (!gtk_gis_layer_source_type)
- {
- static const GTypeInfo gtk_gis_layer_source_info =
- {
- sizeof (GtkGisLayerSourceClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) gtk_gis_layer_source_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GtkGisLayerSource),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gtk_gis_layer_source_init,
- NULL
- };
-
- gtk_gis_layer_source_type = g_type_register_static (G_TYPE_OBJECT, "GtkGisLayerSource",
- >k_gis_layer_source_info, 0);
- }
-
- return gtk_gis_layer_source_type;
-}
+G_DEFINE_TYPE (GtkGisLayerSource, gtk_gis_layer_source, G_TYPE_OBJECT)
static void
gtk_gis_layer_source_class_init (GtkGisLayerSourceClass *klass)
g_type_class_add_private (object_class, sizeof (GtkGisLayerSourcePrivate));
+ klass->set_ogr_datasource = gtk_gis_layer_source_set_ogr_datasource;
+
object_class->set_property = gtk_gis_layer_source_set_property;
object_class->get_property = gtk_gis_layer_source_get_property;
}
GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (gtk_gis_layer_source);
}
+static void
+gtk_gis_layer_source_set_ogr_datasource (GtkGisLayerSource *source,
+ OGRDataSourceH datasource)
+{
+ GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source);
+
+ priv->datasource = datasource;
+}
+
+
/**
* gtk_gis_layer_source_get_geometries:
* @source:
+ * @name:
+ *
+ * Loads the #GtkGisLayerSource from the disk.
*
+ * Returns: .
*/
GList
*gtk_gis_layer_source_get_geometries (GtkGisLayerSource *source,
const gchar *name)
{
- GList *geometries;
+ GList *geometries = NULL;
- if (IS_GTK_GIS_LAYER_SOURCE_OBJECT (source) && GTK_GIS_LAYER_SOURCE_GET_CLASS (source)->get_geometries != NULL)
+ GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source);
+
+ if (priv->datasource == NULL)
+ {
+ /* TO DO */
+ }
+ else
{
- geometries = GTK_GIS_LAYER_SOURCE_GET_CLASS (source)->get_geometries (source, name);
+ OGRLayerH layer;
+ OGRFeatureDefnH layerDefn;
+ OGRFeatureH feature;
+ OGRGeometryH poGeometry;
+ GtkGisGeometry *geometry;
+
+ layer = OGR_DS_GetLayerByName (priv->datasource, name);
+
+ layerDefn = OGR_L_GetLayerDefn (layer);
+
+ while ((feature = OGR_L_GetNextFeature (layer)) != NULL)
+ {
+ poGeometry = OGR_F_GetGeometryRef (feature);
+
+ if (poGeometry != NULL
+ && wkbFlatten(OGR_G_GetGeometryType (poGeometry)) == wkbPoint)
+ {
+ GtkGisPoint gpoint;
+
+ gpoint.x = OGR_G_GetX (poGeometry, 0);
+ gpoint.y = OGR_G_GetY (poGeometry, 0);
+
+ geometry = gtk_gis_geometry_point_new (gpoint);
+ }
+ else if (poGeometry != NULL
+ && wkbFlatten(OGR_G_GetGeometryType (poGeometry)) == wkbLineString)
+ {
+ gint points;
+ gint point;
+ GPtrArray *gar_points;
+
+ GtkGisPoint *gpoint;
+
+ gar_points = g_ptr_array_new ();
+
+ points = OGR_G_GetPointCount (poGeometry);
+
+ for (point = 0; point < points; point++)
+ {
+ gpoint = g_malloc0 (sizeof (GtkGisPoint));
+
+ gpoint->x = OGR_G_GetX (poGeometry, point);
+ gpoint->y = OGR_G_GetY (poGeometry, point);
+
+ g_ptr_array_add (gar_points, gpoint);
+ }
+
+ geometry = gtk_gis_geometry_line_new_from_array (gar_points);
+ }
+ else if (poGeometry != NULL
+ && wkbFlatten(OGR_G_GetGeometryType (poGeometry)) == wkbPolygon)
+ {
+ gint num_geometries;
+ gint i_geometry;
+
+ OGRGeometryH poGeometryIns;
+
+ num_geometries = OGR_G_GetGeometryCount (poGeometry);
+
+ for (i_geometry = 0; i_geometry < num_geometries; i_geometry++)
+ {
+
+ gint points;
+ gint point;
+ GPtrArray *gar_points;
+
+ GtkGisPoint *gpoint;
+
+ poGeometryIns = OGR_G_GetGeometryRef (poGeometry, i_geometry);
+
+ gar_points = g_ptr_array_new ();
+
+ points = OGR_G_GetPointCount (poGeometry);
+
+ for (point = 0; point < points; point++)
+ {
+ gpoint = g_malloc0 (sizeof (GtkGisPoint));
+
+ gpoint->x = OGR_G_GetX (poGeometry, point);
+ gpoint->y = OGR_G_GetY (poGeometry, point);
+
+ g_ptr_array_add (gar_points, gpoint);
+ }
+
+ geometry = gtk_gis_geometry_polygon_new_from_array (gar_points);
+ }
+ }
+
+ geometries = g_list_append (geometries, geometry);
+ }
}
return geometries;
*/
GtkGisLayerGeometryType
gtk_gis_layer_source_get_layer_geometry_type (GtkGisLayerSource *source,
- gchar *name)
+ const 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)
+ OGRLayerH layer;
+ OGRFeatureH feature;
+
+ GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source);
+
+ layer = OGR_DS_GetLayerByName (priv->datasource, name);
+
+ feature = OGR_L_GetNextFeature (layer);
+
+ if (feature != NULL)
{
- type = GTK_GIS_LAYER_SOURCE_GET_CLASS (source)->get_layer_geometry_type (source, name);
+ 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;
+ }
}
return type;
}
+/**
+ * gtk_gis_layer_source_get_layer_extent:
+ * @source:
+ * @name:
+ *
+ * Returns:
+ */
+GtkGisLayerExtent
+gtk_gis_layer_source_get_layer_extent (GtkGisLayerSource *source,
+ const gchar *name)
+{
+ OGRLayerH layer;
+ OGREnvelope psExtent;
+ GtkGisLayerExtent extent;
+
+ GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source);
+
+ layer = OGR_DS_GetLayerByName (priv->datasource, name);
+
+ OGR_L_GetExtent (layer, &psExtent, 1);
+
+ extent.min_x = psExtent.MinX;
+ extent.min_y = psExtent.MinY;
+ extent.max_x = psExtent.MaxX;
+ extent.max_y = psExtent.MaxY;
+
+ return extent;
+}
+
static void
gtk_gis_layer_source_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
- GtkGisLayerSource *gtk_gis_layer_source = GTK_GIS_LAYER_SOURCE (object);
+ GtkGisLayerSource *source = GTK_GIS_LAYER_SOURCE (object);
- GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (gtk_gis_layer_source);
+ GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source);
switch (property_id)
{
static void
gtk_gis_layer_source_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
- GtkGisLayerSource *gtk_gis_layer_source = GTK_GIS_LAYER_SOURCE (object);
+ GtkGisLayerSource *source = GTK_GIS_LAYER_SOURCE (object);
- GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (gtk_gis_layer_source);
+ GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source);
switch (property_id)
{
#include <glib.h>
#include <glib-object.h>
+#include <ogr_api.h>
+#include <ogr_core.h>
+
#include "geometry.h"
G_BEGIN_DECLS
typedef enum
-{
- LAYER_GEOMETRY_TYPE_POINT,
- LAYER_GEOMETRY_TYPE_LINE,
- LAYER_GEOMETRY_TYPE_POLYGON,
- LAYER_GEOMETRY_TYPE_RASTER
-} GtkGisLayerGeometryType;
+ {
+ LAYER_GEOMETRY_TYPE_POINT,
+ LAYER_GEOMETRY_TYPE_LINE,
+ LAYER_GEOMETRY_TYPE_POLYGON,
+ LAYER_GEOMETRY_TYPE_RASTER
+ } GtkGisLayerGeometryType;
+
+typedef struct
+ {
+ gdouble min_x;
+ gdouble min_y;
+ gdouble max_x;
+ gdouble max_y;
+ } GtkGisLayerExtent;
typedef struct _GtkGisLayerSource GtkGisLayerSource;
{
GObjectClass parent_class;
- GList *(*get_geometries) (GtkGisLayerSource *source, const gchar *name);
-
- GtkGisLayerGeometryType (*get_layer_geometry_type) (GtkGisLayerSource *source,
- gchar *name);
+ void (*set_ogr_datasource) (GtkGisLayerSource *source,
+ OGRDataSourceH datasource);
};
GType gtk_gis_layer_source_get_type (void) G_GNUC_CONST;
const gchar *name);
GtkGisLayerGeometryType gtk_gis_layer_source_get_layer_geometry_type (GtkGisLayerSource *source,
- gchar *name);
+ const gchar *name);
+
+GtkGisLayerExtent gtk_gis_layer_source_get_layer_extent (GtkGisLayerSource *source,
+ const gchar *name);
G_END_DECLS
NULL
};
- gtk_gis_layer_source_postgis_type = g_type_register_static (G_TYPE_OBJECT, "GtkGisLayerSourcePostgis",
+ gtk_gis_layer_source_postgis_type = g_type_register_static (TYPE_GTK_GIS_LAYER_SOURCE, "GtkGisLayerSourcePostgis",
>k_gis_layer_source_postgis_info, 0);
}
*
* Returns: the newly created #GtkGisLayerSourcePostgis object.
*/
-GtkGisLayerSourcePostgis
+GtkGisLayerSource
*gtk_gis_layer_source_postgis_new (gchar *host,
gint port,
gchar *username,
gchar *password)
{
- GtkGisLayerSourcePostgis *gtk_gis_layer_source_postgis;
+ GtkGisLayerSource *source;
GtkGisLayerSourcePostgisPrivate *priv;
- gtk_gis_layer_source_postgis = GTK_GIS_LAYER_SOURCE_POSTGIS (g_object_new (gtk_gis_layer_source_postgis_get_type (), NULL));
+ source = 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 = GTK_GIS_LAYER_SOURCE_POSTGIS_GET_PRIVATE (GTK_GIS_LAYER_SOURCE_POSTGIS (source));
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;
+ return source;
}
static void
gtk_gis_layer_source_postgis_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
- GtkGisLayerSourcePostgis *gtk_gis_layer_source_postgis = GTK_GIS_LAYER_SOURCE_POSTGIS (object);
+ GtkGisLayerSourcePostgis *source = GTK_GIS_LAYER_SOURCE_POSTGIS (object);
- GtkGisLayerSourcePostgisPrivate *priv = GTK_GIS_LAYER_SOURCE_POSTGIS_GET_PRIVATE (gtk_gis_layer_source_postgis);
+ GtkGisLayerSourcePostgisPrivate *priv = GTK_GIS_LAYER_SOURCE_POSTGIS_GET_PRIVATE (source);
switch (property_id)
{
static void
gtk_gis_layer_source_postgis_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
- GtkGisLayerSourcePostgis *gtk_gis_layer_source_postgis = GTK_GIS_LAYER_SOURCE_POSTGIS (object);
+ GtkGisLayerSourcePostgis *source = GTK_GIS_LAYER_SOURCE_POSTGIS (object);
- GtkGisLayerSourcePostgisPrivate *priv = GTK_GIS_LAYER_SOURCE_POSTGIS_GET_PRIVATE (gtk_gis_layer_source_postgis);
+ GtkGisLayerSourcePostgisPrivate *priv = GTK_GIS_LAYER_SOURCE_POSTGIS_GET_PRIVATE (source);
switch (property_id)
{
GType gtk_gis_layer_source_postgis_get_type (void) G_GNUC_CONST;
-GtkGisLayerSourcePostgis *gtk_gis_layer_source_postgis_new (gchar *host,
- gint port,
- gchar *username,
- gchar *password);
+GtkGisLayerSource *gtk_gis_layer_source_postgis_new (gchar *host,
+ gint port,
+ gchar *username,
+ gchar *password);
G_END_DECLS
#include <ogr_core.h>
#include "layersourceshp.h"
-#include "geometryline.h"
-#include "geometrypoint.h"
-#include "geometrypolygon.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_ogr_datasource (GtkGisLayerSource *source,
+ OGRDataSourceH datasource);
static void gtk_gis_layer_source_shp_set_property (GObject *object,
guint property_id,
struct _GtkGisLayerSourceShpPrivate
{
gchar *filename;
-
- OGRDataSourceH datasource;
};
GType
NULL
};
- gtk_gis_layer_source_shp_type = g_type_register_static (G_TYPE_OBJECT, "GtkGisLayerSourceShp",
+ gtk_gis_layer_source_shp_type = g_type_register_static (TYPE_GTK_GIS_LAYER_SOURCE, "GtkGisLayerSourceShp",
>k_gis_layer_source_shp_info, 0);
}
object_class->set_property = gtk_gis_layer_source_shp_set_property;
object_class->get_property = gtk_gis_layer_source_shp_get_property;
-
- gtkgislayersource_class->get_geometries = gtk_gis_layer_source_shp_get_geometries;
- gtkgislayersource_class->get_layer_geometry_type = gtk_gis_layer_source_shp_get_layer_geometry_type;
}
static void
*
* Returns: the newly created #GtkGisLayerSourceShp object.
*/
-GtkGisLayerSourceShp
-*gtk_gis_layer_source_shp_new (gchar *filename)
+GtkGisLayerSource
+*gtk_gis_layer_source_shp_new (const gchar *filename)
{
- GtkGisLayerSourceShp *gtk_gis_layer_source_shp;
+ GtkGisLayerSource *source;
+ GtkGisLayerSourceShpPrivate *priv;
- gtk_gis_layer_source_shp = GTK_GIS_LAYER_SOURCE_SHP (g_object_new (gtk_gis_layer_source_shp_get_type (), NULL));
+ source = 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 = GTK_GIS_LAYER_SOURCE_SHP_GET_PRIVATE (GTK_GIS_LAYER_SOURCE_SHP (source));
priv->filename = g_strdup (filename);
OGRRegisterAll ();
/* Open data source */
- priv->datasource = OGROpen (priv->filename, 0 /* bUpdate */, NULL);
+ gtk_gis_layer_source_shp_set_ogr_datasource (source,
+ OGROpen (priv->filename, 0 /* bUpdate */, NULL));
- return gtk_gis_layer_source_shp;
+ return source;
}
/**
return g_strdup (priv->filename);
}
-/**
- * gtk_gis_layer_source_shp_get_geometries:
- * @source:
- * @name:
- *
- * Loads the #GtkGisLayerSource from the disk.
- *
- * Returns: .
- */
-GList
-*gtk_gis_layer_source_shp_get_geometries (GtkGisLayerSource *source,
- const gchar *name)
+static void
+gtk_gis_layer_source_shp_set_ogr_datasource (GtkGisLayerSource *source,
+ OGRDataSourceH datasource)
{
- GList *geometries = NULL;
-
- GtkGisLayerSourceShpPrivate *priv = GTK_GIS_LAYER_SOURCE_SHP_GET_PRIVATE (source);
-
- if (priv->datasource == NULL)
- {
- /* TO DO */
- }
- else
+ if (IS_GTK_GIS_LAYER_SOURCE (source) && GTK_GIS_LAYER_SOURCE_GET_CLASS (source)->set_ogr_datasource != NULL)
{
- gint numLayers;
- gint i;
-
- OGRLayerH layer;
- OGRFeatureDefnH layerDefn;
-
- GtkGisLayerSourceShpPrivate *priv = GTK_GIS_LAYER_SOURCE_SHP_GET_PRIVATE (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;
- OGRGeometryH poGeometry;
- GtkGisGeometry *geometry;
-
- while ((feature = OGR_L_GetNextFeature (layer)) != NULL)
- {
- poGeometry = OGR_F_GetGeometryRef (feature);
- if (poGeometry != NULL
- && wkbFlatten(OGR_G_GetGeometryType (poGeometry)) == wkbPoint)
- {
- geometry = GTK_GIS_GEOMETRY (gtk_gis_geometry_point_new (OGR_G_GetX (poGeometry, 0), OGR_G_GetY (poGeometry, 0)));
- }
- else if (poGeometry != NULL
- && wkbFlatten(OGR_G_GetGeometryType (poGeometry)) == wkbLineString)
- {
- }
- else if (poGeometry != NULL
- && wkbFlatten(OGR_G_GetGeometryType (poGeometry)) == wkbPolygon)
- {
- }
-
- geometries = g_list_append (geometries, geometry);
- }
-
- break;
- }
- }
- }
-
- return geometries;
-}
-
-/**
- * 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 (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;
- }
+ GTK_GIS_LAYER_SOURCE_GET_CLASS (source)->set_ogr_datasource (source, datasource);
}
-
- return type;
}
static void
gtk_gis_layer_source_shp_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
- GtkGisLayerSourceShp *gtk_gis_layer_source_shp = GTK_GIS_LAYER_SOURCE_SHP (object);
+ GtkGisLayerSourceShp *source = GTK_GIS_LAYER_SOURCE_SHP (object);
- GtkGisLayerSourceShpPrivate *priv = GTK_GIS_LAYER_SOURCE_SHP_GET_PRIVATE (gtk_gis_layer_source_shp);
+ GtkGisLayerSourceShpPrivate *priv = GTK_GIS_LAYER_SOURCE_SHP_GET_PRIVATE (source);
switch (property_id)
{
static void
gtk_gis_layer_source_shp_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
- GtkGisLayerSourceShp *gtk_gis_layer_source_shp = GTK_GIS_LAYER_SOURCE_SHP (object);
+ GtkGisLayerSourceShp *source = GTK_GIS_LAYER_SOURCE_SHP (object);
- GtkGisLayerSourceShpPrivate *priv = GTK_GIS_LAYER_SOURCE_SHP_GET_PRIVATE (gtk_gis_layer_source_shp);
+ GtkGisLayerSourceShpPrivate *priv = GTK_GIS_LAYER_SOURCE_SHP_GET_PRIVATE (source);
switch (property_id)
{
GType gtk_gis_layer_source_shp_get_type (void) G_GNUC_CONST;
-GtkGisLayerSourceShp *gtk_gis_layer_source_shp_new (gchar *filename);
+GtkGisLayerSource *gtk_gis_layer_source_shp_new (const gchar *filename);
gchar *gtk_gis_layer_get_filename (GtkGisLayerSourceShp *source);
-GList *gtk_gis_layer_source_shp_get_geometries (GtkGisLayerSource *source, const gchar *name);
-
-GtkGisLayerGeometryType gtk_gis_layer_source_shp_get_layer_geometry_type (GtkGisLayerSource *source,
- gchar *name);
-
G_END_DECLS
SUBDIRS = samples
-LIBS = $(GTKGIS_LIBS)
+LIBS = $(GTKGIS_LIBS) \
+ $(GDAL_LIBS)
AM_CPPFLAGS = $(GTKGIS_CFLAGS) \
+ $(GDAL_CFLAGS) \
-I$(top_srcdir)/src
libgtkgis = $(top_builddir)/src/libgtkgis.la
-noinst_PROGRAMS = from_xml
+LDADD = $(libgtkgis)
-LDADD = $(libgtgkis)
+noinst_PROGRAMS = from_xml
EXTRA_DIST = test1.gtkgis
int
main (int argc, char *argv[])
{
+ GtkWidget *window;
+ GtkWidget *gtkgis;
+
+ gtk_init (&argc, &argv);
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size (GTK_WINDOW (window), 640, 600);
+
+ g_signal_connect (window, "delete_event", (GtkSignalFunc) gtk_main_quit,
+ NULL);
+
+ gtkgis = gtk_gis_new_from_file (argv[1]);
+
+ gtk_container_add (GTK_CONTAINER (window), gtkgis);
+
+ gtk_widget_show_all (window);
+
+ gtk_main ();
+
return 0;
}
<layer name="alaska">
<source>
- <shape filename="samples\alaska.shp" />
+ <shape filename="/home/andreaz/files/c/libgtkgis/tests/samples/alaska.shp" />
</source>
</layer>
- <layer name="airports">
+ <!--<layer name="airports">
<source>
- <shape filename="samples\airports.shp" />
+ <shape filename="samples/airports.shp" />
</source>
</layer>
<layer name="railroads">
<source>
- <shape filename="samples\railroads.shp" />
+ <shape filename="samples/railroads.shp" />
</source>
</layer>
<layer name="rivers">
<source>
- <shape filename="samples\rivers.shp" />
+ <shape filename="samples/rivers.shp" />
</source>
- </layer>
+ </layer>-->
</gtkgis>