From 3487804553eff760602e37b36f85a9ebc500ea0f Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Thu, 6 Aug 2009 22:47:06 +0200 Subject: [PATCH] Added GtkGis::zoom_to_extent (not complete). Added GtkGis::move_to. Implemented layer's visibility (yes or not). --- docs/reference/libgtkgis-decl-list.txt | 4 + docs/reference/libgtkgis-decl.txt | 23 ++++- docs/reference/libgtkgis-undocumented.txt | 6 +- docs/reference/libgtkgis-unused.txt | 4 + docs/reference/tmpl/commons.sgml | 1 + src/commons.h | 1 + src/gtkgis.c | 116 ++++++++++++++++++++- src/gtkgis.h | 3 + src/layer.c | 118 +++++++++++++++++++--- src/layer.h | 4 + src/layersource.c | 70 +++++++------ src/layersource.h | 4 +- tests/from_xml.c | 15 ++- tests/test1.gtkgis | 2 +- 14 files changed, 313 insertions(+), 58 deletions(-) diff --git a/docs/reference/libgtkgis-decl-list.txt b/docs/reference/libgtkgis-decl-list.txt index 3d4d57a..4297a60 100644 --- a/docs/reference/libgtkgis-decl-list.txt +++ b/docs/reference/libgtkgis-decl-list.txt @@ -74,8 +74,10 @@ gtk_gis_get_layer_by_name gtk_gis_draw gtk_gis_get_scale gtk_gis_set_scale +gtk_gis_zoom_to_extent gtk_gis_zoom_to_max gtk_gis_zoom_to_layer +gtk_gis_move_to gtk_gis_get_legend @@ -118,6 +120,8 @@ gtk_gis_layer_save gtk_gis_layer_add_geometry gtk_gis_layer_remove_geometry gtk_gis_layer_get_extent +gtk_gis_layer_get_visible +gtk_gis_layer_set_visible gtk_gis_layer_get_editable gtk_gis_layer_set_editable gtk_gis_layer_get_style diff --git a/docs/reference/libgtkgis-decl.txt b/docs/reference/libgtkgis-decl.txt index f93f135..099171a 100644 --- a/docs/reference/libgtkgis-decl.txt +++ b/docs/reference/libgtkgis-decl.txt @@ -325,6 +325,11 @@ GtkGis *gtkgis GtkGis *gtkgis, GtkGisScale *scale +gtk_gis_zoom_to_extent +void +GtkGis *gtkgis, GtkGisLayerExtent extent + + gtk_gis_zoom_to_max void GtkGis *gtkgis @@ -335,6 +340,11 @@ GtkGis *gtkgis GtkGis *gtkgis, GtkGisLayer *layer +gtk_gis_move_to +void +GtkGis *gtkgis, gdouble x, gdouble y + + gtk_gis_get_legend GtkWidget * GtkGis *gtkgis @@ -513,6 +523,16 @@ GtkGisLayer *layer,GtkGisGeometry *geometry GtkGisLayer *layer +gtk_gis_layer_get_visible +gboolean +GtkGisLayer *layer + + +gtk_gis_layer_set_visible +void +GtkGisLayer *layer,gboolean visible + + gtk_gis_layer_get_editable gboolean GtkGisLayer *layer @@ -865,7 +885,7 @@ GtkGisLayerSource *source gtk_gis_layer_source_get_geometries -GList * +GSList * GtkGisLayerSource *source,const gchar *name @@ -887,6 +907,7 @@ GtkGisLayerSource *source,GtkGisLayerExtent *extent GtkGisLayerGeometryType typedef enum { + LAYER_GEOMETRY_TYPE_UNKNOWN, LAYER_GEOMETRY_TYPE_POINT, LAYER_GEOMETRY_TYPE_LINE, LAYER_GEOMETRY_TYPE_POLYGON, diff --git a/docs/reference/libgtkgis-undocumented.txt b/docs/reference/libgtkgis-undocumented.txt index d61db35..9e381ac 100644 --- a/docs/reference/libgtkgis-undocumented.txt +++ b/docs/reference/libgtkgis-undocumented.txt @@ -1,7 +1,7 @@ 11% symbol docs coverage. 22 symbols documented. 7 symbols incomplete. -171 not documented. +175 not documented. GTK_GIS @@ -123,10 +123,12 @@ gtk_gis_layer_get_name gtk_gis_layer_get_source gtk_gis_layer_get_style gtk_gis_layer_get_type +gtk_gis_layer_get_visible gtk_gis_layer_get_xml gtk_gis_layer_new (geometrytype, geometry_type) gtk_gis_layer_remove_geometry gtk_gis_layer_set_editable +gtk_gis_layer_set_visible gtk_gis_layer_source_get_geometries (name, name) gtk_gis_layer_source_get_layer_extent gtk_gis_layer_source_get_layer_geometry_type @@ -147,12 +149,14 @@ gtk_gis_layers_group_get_type gtk_gis_layers_group_new (source, name, geometrytype, name) gtk_gis_layers_group_remove_layer gtk_gis_layers_group_set_name +gtk_gis_move_to gtk_gis_new_from_file gtk_gis_new_from_xml gtk_gis_remove_group gtk_gis_remove_layer gtk_gis_save_to_xml gtk_gis_set_scale +gtk_gis_zoom_to_extent gtk_gis_zoom_to_layer gtk_gis_zoom_to_max diff --git a/docs/reference/libgtkgis-unused.txt b/docs/reference/libgtkgis-unused.txt index 36fa92a..65ad8c0 100644 --- a/docs/reference/libgtkgis-unused.txt +++ b/docs/reference/libgtkgis-unused.txt @@ -12,4 +12,8 @@ GtkGisLayerSourceShpClass GtkGisLayersGroupClass gtk_gis_geometry_line_get_svg_path gtk_gis_layer_get_style +gtk_gis_layer_get_visible gtk_gis_layer_set_style +gtk_gis_layer_set_visible +gtk_gis_move_to +gtk_gis_zoom_to_extent diff --git a/docs/reference/tmpl/commons.sgml b/docs/reference/tmpl/commons.sgml index a0a520d..607de02 100644 --- a/docs/reference/tmpl/commons.sgml +++ b/docs/reference/tmpl/commons.sgml @@ -22,6 +22,7 @@ commons +@LAYER_GEOMETRY_TYPE_UNKNOWN: @LAYER_GEOMETRY_TYPE_POINT: @LAYER_GEOMETRY_TYPE_LINE: @LAYER_GEOMETRY_TYPE_POLYGON: diff --git a/src/commons.h b/src/commons.h index 5dcd2ee..e71b9c6 100644 --- a/src/commons.h +++ b/src/commons.h @@ -56,6 +56,7 @@ typedef struct typedef enum { + LAYER_GEOMETRY_TYPE_UNKNOWN, LAYER_GEOMETRY_TYPE_POINT, LAYER_GEOMETRY_TYPE_LINE, LAYER_GEOMETRY_TYPE_POLYGON, diff --git a/src/gtkgis.c b/src/gtkgis.c index d176a07..210d349 100644 --- a/src/gtkgis.c +++ b/src/gtkgis.c @@ -192,7 +192,7 @@ GtkWidget cur = xmlDocGetRootElement (xdoc); if (cur != NULL) { - if (strcmp (cur->name, "gtkgis") == 0) + if (xmlStrcmp (cur->name, "gtkgis") == 0) { GtkGisPrivate *priv; @@ -208,6 +208,8 @@ GtkWidget { xmlNode *xml_layer; gchar *layer_name; + gchar *visible; + gboolean is_visible; GtkGisLayer *layer; xml_layer = cur; @@ -217,9 +219,17 @@ GtkWidget { /* TO DO */ /* get layer source name */ - layer_name = g_strdup_printf ("layer"); + layer_name = g_strdup ("layer"); } + visible = xmlGetProp (cur, (const xmlChar *)"visible"); + if (visible == NULL || + g_strcmp0 (g_strstrip (visible), "") == 0) + { + visible = g_strdup ("y"); + } + is_visible = (g_strcmp0 (visible, "y") == 0); + /* TO DO * don't use a cycle: first find source and then style */ @@ -262,6 +272,10 @@ GtkWidget if (layer_source != NULL) { layer = gtk_gis_layer_new_from_source (layer_source, layer_name); + if (!is_visible) + { + gtk_gis_layer_set_visible (layer, is_visible); + } gtk_gis_add_layer (GTK_GIS (gtkgis), layer); } @@ -632,6 +646,75 @@ gtk_gis_set_scale (GtkGis *gtkgis, GtkGisScale *scale) gdk_window_set_cursor (GTK_WIDGET (gtkgis)->window, NULL); } +/** + * gtk_gis_zoom_to_extent: + * @gtkgis: a #GtkGis object. + * @extent: a #GtkGisLayerExtent struct. + * + */ +void +gtk_gis_zoom_to_extent (GtkGis *gtkgis, GtkGisLayerExtent extent) +{ + GtkGisPrivate *priv; + GtkGisScale *scale; + + gdouble extx; + gdouble exty; + + gdouble widget_width; + gdouble widget_height; + + gdouble extent_width; + gdouble extent_height; + + gdouble ratio; + gdouble plus; + + g_return_if_fail (IS_GTK_GIS (gtkgis)); + + priv = GTK_GIS_GET_PRIVATE (gtkgis); + + extx = 1.0; + exty = 1.0; + + widget_width = GTK_WIDGET (gtkgis)->allocation.width; + widget_height = GTK_WIDGET (gtkgis)->allocation.height; + + scale = g_malloc0 (sizeof (GtkGisScale)); + + /* must add width or height to make the max extent + * the same proportion of the canvas */ + extent_width = extent.max_x - extent.min_x; + extent_height = extent.max_y - extent.min_y; + + ratio = widget_width / widget_height; + + plus = extent_width / ratio; + + if (plus > extent_height) + { + plus = (plus - extent_height) / 2; + extent.min_y -= plus; + extent.max_y += plus; + } + else + { + plus = extent_height * ratio; + plus = (plus - extent_width) / 2; + extent.min_x -= plus; + extent.max_x += plus; + } + + extx = extent.max_x - extent.min_x; + exty = extent.max_y - extent.min_y; + + scale->x = widget_width / extx; + scale->y = widget_height / exty; + scale->xy = (scale->x + scale->y) / 2; + + gtk_gis_set_scale (gtkgis, scale); +} + /** * gtk_gis_zoom_to_max: * @gtkgis: a #GtkGis object. @@ -716,13 +799,42 @@ gtk_gis_zoom_to_max (GtkGis *gtkgis) */ void gtk_gis_zoom_to_layer (GtkGis *gtkgis, GtkGisLayer *layer) +{ + GtkGisLayerExtent *extent; + + g_return_if_fail (IS_GTK_GIS (gtkgis)); + g_return_if_fail (IS_GTK_GIS_LAYER (layer)); + + extent = gtk_gis_layer_get_extent (layer); + gtk_gis_zoom_to_extent (gtkgis, *extent); + + gtk_gis_move_to (gtkgis, extent->min_x, extent->min_y); +} + +/** + * gtk_gis_move_to: + * @gtkgis: + * @x: + * @y: + * + */ +void +gtk_gis_move_to (GtkGis *gtkgis, gdouble x, gdouble y) { GtkGisPrivate *priv; + gdouble new_x; + gdouble new_y; g_return_if_fail (IS_GTK_GIS (gtkgis)); priv = GTK_GIS_GET_PRIVATE (gtkgis); + new_x = x; + new_y = y; + goo_canvas_convert_to_pixels (GOO_CANVAS (priv->canvas), &new_x, &new_y); + + gtk_layout_move (GTK_LAYOUT (priv->scroll_win), priv->canvas, + -new_x, -new_y); } static void diff --git a/src/gtkgis.h b/src/gtkgis.h index 2626b28..5db9e27 100644 --- a/src/gtkgis.h +++ b/src/gtkgis.h @@ -75,9 +75,12 @@ void gtk_gis_draw (GtkGis *gtkgis); GtkGisScale *gtk_gis_get_scale (GtkGis *gtkgis); void gtk_gis_set_scale (GtkGis *gtkgis, GtkGisScale *scale); +void gtk_gis_zoom_to_extent (GtkGis *gtkgis, GtkGisLayerExtent extent); void gtk_gis_zoom_to_max (GtkGis *gtkgis); void gtk_gis_zoom_to_layer (GtkGis *gtkgis, GtkGisLayer *layer); +void gtk_gis_move_to (GtkGis *gtkgis, gdouble x, gdouble y); + GtkWidget *gtk_gis_get_legend (GtkGis *gtkgis); diff --git a/src/layer.c b/src/layer.c index a7c86c7..c0d40f5 100644 --- a/src/layer.c +++ b/src/layer.c @@ -52,8 +52,9 @@ struct _GtkGisLayerPrivate GtkGisLayerSource *source; GooCanvasItem *layer_item; - GList *geometries; + GSList *geometries; + gboolean visible; gboolean editable; GtkGisLayerStyle *style; @@ -77,6 +78,9 @@ gtk_gis_layer_init (GtkGisLayer *gtk_gis_layer) { GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (gtk_gis_layer); + priv->visible = TRUE; + priv->editable = FALSE; + priv->style = g_malloc (sizeof (GtkGisLayerStyle)); priv->style->width = 0.5; priv->style->stroke_color = g_strdup ("black"); @@ -196,7 +200,11 @@ gchar GtkGisLayerSource *gtk_gis_layer_get_source (GtkGisLayer *layer) { - GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + GtkGisLayerPrivate *priv; + + g_return_val_if_fail (IS_GTK_GIS_LAYER (layer), NULL); + + priv = GTK_GIS_LAYER_GET_PRIVATE (layer); return priv->source; } @@ -211,7 +219,11 @@ GtkGisLayerSource void gtk_gis_layer_fill_from_source (GtkGisLayer *layer) { - GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + GtkGisLayerPrivate *priv; + + g_return_if_fail (IS_GTK_GIS_LAYER (layer)); + + priv = GTK_GIS_LAYER_GET_PRIVATE (layer); priv->geometries = gtk_gis_layer_source_get_geometries (priv->source, priv->name); } @@ -238,9 +250,14 @@ gtk_gis_layer_save (GtkGisLayer *layer, void gtk_gis_layer_add_geometry (GtkGisLayer *layer, GtkGisGeometry *geometry) { - GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + GtkGisLayerPrivate *priv; + + g_return_if_fail (IS_GTK_GIS_LAYER (layer)); + g_return_if_fail (IS_GTK_GIS_GEOMETRY (geometry)); + + priv = GTK_GIS_LAYER_GET_PRIVATE (layer); - priv->geometries = g_list_append (priv->geometries, geometry); + priv->geometries = g_slist_append (priv->geometries, geometry); } /** @@ -251,9 +268,14 @@ gtk_gis_layer_add_geometry (GtkGisLayer *layer, GtkGisGeometry *geometry) void gtk_gis_layer_remove_geometry (GtkGisLayer *layer, GtkGisGeometry *geometry) { - GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + GtkGisLayerPrivate *priv; - priv->geometries = g_list_remove (priv->geometries, geometry); + g_return_if_fail (IS_GTK_GIS_LAYER (layer)); + g_return_if_fail (IS_GTK_GIS_GEOMETRY (geometry)); + + priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + + priv->geometries = g_slist_remove (priv->geometries, geometry); } /** @@ -264,15 +286,54 @@ gtk_gis_layer_remove_geometry (GtkGisLayer *layer, GtkGisGeometry *geometry) GtkGisLayerExtent *gtk_gis_layer_get_extent (GtkGisLayer *layer) { - GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer); - + GtkGisLayerPrivate *priv; GtkGisLayerExtent *extent; + g_return_val_if_fail (IS_GTK_GIS_LAYER (layer), NULL); + + priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + extent = gtk_gis_layer_source_get_layer_extent (priv->source, priv->name); return extent; } +/** + * gtk_gis_layer_get_visible: + * @layer: a #GtkGisLayer object. + * + * Returns: whether the layer is visible. + */ +gboolean +gtk_gis_layer_get_visible (GtkGisLayer *layer) +{ + GtkGisLayerPrivate *priv; + + g_return_val_if_fail (IS_GTK_GIS_LAYER (layer), FALSE); + + priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + + return priv->visible; +} + +/** + * gtk_gis_layer_set_visible: + * @layer: a #GtkGisLayer object. + * @visible: + */ +void +gtk_gis_layer_set_visible (GtkGisLayer *layer, + gboolean visible) +{ + GtkGisLayerPrivate *priv; + + g_return_if_fail (IS_GTK_GIS_LAYER (layer)); + + priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + + priv->visible = visible; +} + /** * gtk_gis_layer_get_editable: * @layer: a #GtkGisLayer object. @@ -282,7 +343,11 @@ GtkGisLayerExtent gboolean gtk_gis_layer_get_editable (GtkGisLayer *layer) { - GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + GtkGisLayerPrivate *priv; + + g_return_val_if_fail (IS_GTK_GIS_LAYER (layer), FALSE); + + priv = GTK_GIS_LAYER_GET_PRIVATE (layer); return priv->editable; } @@ -296,7 +361,11 @@ void gtk_gis_layer_set_editable (GtkGisLayer *layer, gboolean editable) { - GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + GtkGisLayerPrivate *priv; + + g_return_if_fail (IS_GTK_GIS_LAYER (layer)); + + priv = GTK_GIS_LAYER_GET_PRIVATE (layer); priv->editable = editable; } @@ -336,6 +405,7 @@ gtk_gis_layer_set_style (GtkGisLayer *layer, GtkGisLayerStyle style) { GtkGisLayerPrivate *priv; GtkGisLayerStyle new_style; + gchar *prop; g_return_if_fail (IS_GTK_GIS_LAYER (layer)); @@ -349,7 +419,10 @@ gtk_gis_layer_set_style (GtkGisLayer *layer, GtkGisLayerStyle style) { new_style.width = priv->style->width; } - if (style.stroke_color != NULL) + + prop = g_strdup (style.stroke_color); + if (style.stroke_color != NULL && + g_strcmp0 (g_strstrip (prop), "") != 0) { new_style.stroke_color = g_strdup (style.stroke_color); } @@ -357,7 +430,10 @@ gtk_gis_layer_set_style (GtkGisLayer *layer, GtkGisLayerStyle style) { new_style.stroke_color = g_strdup (priv->style->stroke_color); } - if (style.fill_color != NULL) + + prop = g_strdup (style.fill_color); + if (style.fill_color != NULL && + g_strcmp0 (g_strstrip (prop), "") != 0) { new_style.fill_color = g_strdup (style.fill_color); } @@ -381,7 +457,7 @@ void gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale) { GtkGisLayerPrivate *priv; - GList *cur; + GSList *cur; GooCanvasItem *item; g_return_if_fail (IS_GTK_GIS_LAYER (layer)); @@ -389,11 +465,21 @@ gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale) priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + if (!priv->visible) + { + /* TO DO + * free each geometry before + */ + g_free (priv->geometries); + priv->geometries = NULL; + return; + } + gtk_gis_layer_fill_from_source (layer); priv->layer_item = goo_canvas_group_new (root, NULL); - cur = g_list_first (priv->geometries); + cur = priv->geometries; while (cur != NULL) { item = gtk_gis_geometry_draw ((GtkGisGeometry *)cur->data, scale, *priv->style); @@ -403,7 +489,7 @@ gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale) goo_canvas_item_add_child (priv->layer_item, item, -1); } - cur = g_list_next (cur); + cur = g_slist_next (cur); } } diff --git a/src/layer.h b/src/layer.h index 13d42f3..da1c173 100644 --- a/src/layer.h +++ b/src/layer.h @@ -83,6 +83,10 @@ void gtk_gis_layer_remove_geometry (GtkGisLayer *layer, GtkGisLayerExtent *gtk_gis_layer_get_extent (GtkGisLayer *layer); +gboolean gtk_gis_layer_get_visible (GtkGisLayer *layer); +void gtk_gis_layer_set_visible (GtkGisLayer *layer, + gboolean visible); + gboolean gtk_gis_layer_get_editable (GtkGisLayer *layer); void gtk_gis_layer_set_editable (GtkGisLayer *layer, gboolean editable); diff --git a/src/layersource.c b/src/layersource.c index b9548f3..ff83156 100644 --- a/src/layersource.c +++ b/src/layersource.c @@ -30,10 +30,10 @@ static void gtk_gis_layer_source_class_init (GtkGisLayerSourceClass *klass); static void gtk_gis_layer_source_init (GtkGisLayerSource *gtk_gis_layer_source); -static GList +static GSList *gtk_gis_layer_source_get_geometries_from_ogr (GtkGisLayerSource *source, const gchar *name); -static GList +static GSList *gtk_gis_layer_source_get_geometries_from_gdal (GtkGisLayerSource *source, const gchar *name); @@ -119,13 +119,13 @@ xmlNode * * Loads the #GtkGisLayerSource from the disk. * - * Returns: a #GList of #GtkGeometry objects. + * Returns: a #GSList of #GtkGeometry objects. */ -GList +GSList *gtk_gis_layer_source_get_geometries (GtkGisLayerSource *source, const gchar *name) { - GList *geometries = NULL; + GSList *geometries = NULL; GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source); @@ -152,38 +152,46 @@ GtkGisLayerGeometryType gtk_gis_layer_source_get_layer_geometry_type (GtkGisLayerSource *source, const gchar *name) { - GtkGisLayerGeometryType type = -1; + GtkGisLayerGeometryType type; OGRLayerH layer; OGRFeatureH feature; - GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source); + GtkGisLayerSourcePrivate *priv; + + g_return_val_if_fail (IS_GTK_GIS_LAYER_SOURCE (source), LAYER_GEOMETRY_TYPE_UNKNOWN); + priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source); + + type = LAYER_GEOMETRY_TYPE_UNKNOWN; if (priv->datasource != NULL) { layer = OGR_DS_GetLayerByName (priv->datasource, name); - feature = OGR_L_GetNextFeature (layer); - - if (feature != NULL) + if (layer != NULL) { - OGRGeometryH poGeometry; + feature = OGR_L_GetNextFeature (layer); - 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) + if (feature != NULL) { - type = LAYER_GEOMETRY_TYPE_POLYGON; + 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; + } } } } @@ -302,11 +310,11 @@ gtk_gis_layer_source_set_gdal_dataset (GtkGisLayerSource *source, priv->max_extent = NULL; } -static GList +static GSList *gtk_gis_layer_source_get_geometries_from_ogr (GtkGisLayerSource *source, const gchar *name) { - GList *geometries = NULL; + GSList *geometries = NULL; OGRLayerH layer; OGRFeatureH feature; @@ -416,17 +424,17 @@ static GList } } - geometries = g_list_append (geometries, geometry); + geometries = g_slist_append (geometries, geometry); } return geometries; } -static GList +static GSList *gtk_gis_layer_source_get_geometries_from_gdal (GtkGisLayerSource *source, const gchar *name) { - GList *geometries = NULL; + GSList *geometries = NULL; GtkGisGeometry *geometry; gdouble adfGeoTransform[6]; @@ -543,7 +551,7 @@ static GList if (geometry != NULL) { - geometries = g_list_append (geometries, geometry); + geometries = g_slist_append (geometries, geometry); } } diff --git a/src/layersource.h b/src/layersource.h index c1508a6..50108c3 100644 --- a/src/layersource.h +++ b/src/layersource.h @@ -68,8 +68,8 @@ GType gtk_gis_layer_source_get_type (void) G_GNUC_CONST; xmlNode *gtk_gis_layer_source_get_xml (GtkGisLayerSource *source); -GList *gtk_gis_layer_source_get_geometries (GtkGisLayerSource *source, - const gchar *name); +GSList *gtk_gis_layer_source_get_geometries (GtkGisLayerSource *source, + const gchar *name); GtkGisLayerGeometryType gtk_gis_layer_source_get_layer_geometry_type (GtkGisLayerSource *source, const gchar *name); diff --git a/tests/from_xml.c b/tests/from_xml.c index 2182bd0..fb7d49a 100644 --- a/tests/from_xml.c +++ b/tests/from_xml.c @@ -16,22 +16,29 @@ main (int argc, char *argv[]) NULL); gtkgis = gtk_gis_new_from_file (argv[1]); + if (gtkgis == NULL) + { + g_fprintf (stderr, "Error loading GtkGis definition file.\n"); + return 0; + } - gtk_container_add (GTK_CONTAINER (window), gtkgis); + gtk_container_add (GTK_CONTAINER (window), gtkgis); gtk_widget_show_all (window); - gtk_gis_zoom_to_max (GTK_GIS (gtkgis)); + /*gtk_gis_zoom_to_max (GTK_GIS (gtkgis));*/ + gtk_gis_zoom_to_layer (GTK_GIS (gtkgis), + gtk_gis_get_layer_by_name (GTK_GIS (gtkgis), "railroads")); gtk_gis_draw (GTK_GIS (gtkgis)); - scale = gtk_gis_get_scale (GTK_GIS (gtkgis)); + /*scale = gtk_gis_get_scale (GTK_GIS (gtkgis)); if (scale != NULL) { scale->x = (scale->x * 80) / 100; scale->y = (scale->y * 80) / 100; scale->xy = (scale->xy * 80) / 100; gtk_gis_set_scale (GTK_GIS (gtkgis), scale); - } + }*/ gtk_gis_save_to_xml (GTK_GIS (gtkgis), "test_saved.gtkgis"); diff --git a/tests/test1.gtkgis b/tests/test1.gtkgis index 3910e04..33d044e 100644 --- a/tests/test1.gtkgis +++ b/tests/test1.gtkgis @@ -24,7 +24,7 @@ - + -- 2.49.0