From b9f3e7cb5f45b4131ff021ae9f2ee73c1e8506c9 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 4 Jul 2009 16:36:48 +0200 Subject: [PATCH] Fixed bug on GtkGisGeomtryPolygon with multiple geometries. Added GtkGisGeometry::add_line_from_list. Added support for relative filename path. --- src/geometrypolygon.c | 27 +++++++++++++++++++++++---- src/geometrypolygon.h | 1 + src/gtkgis.c | 18 +++++++++++++++++- src/layersource.c | 19 +++++++++++++------ tests/test1.gtkgis | 16 ++++++++-------- 5 files changed, 62 insertions(+), 19 deletions(-) diff --git a/src/geometrypolygon.c b/src/geometrypolygon.c index 27af4ab..1887207 100644 --- a/src/geometrypolygon.c +++ b/src/geometrypolygon.c @@ -149,6 +149,26 @@ gtk_gis_geometry_polygon_add_line (GtkGisGeometryPolygon *polygon, priv->lines = g_slist_append (priv->lines, line); } +/** + * gtk_gis_geometry_polygon_add_line_from_list: + * @polygon: + * @points: + * + */ +void +gtk_gis_geometry_polygon_add_line_from_list (GtkGisGeometryPolygon *polygon, + GSList *points) +{ + GtkGisGeometry *line; + + line = gtk_gis_geometry_line_new_from_list (points); + + if (line != NULL) + { + gtk_gis_geometry_polygon_add_line (polygon, GTK_GIS_GEOMETRY_LINE (line)); + } +} + /** * gtk_gis_geometry_polygon_remove_line: * @polygon: @@ -177,18 +197,17 @@ static GooCanvasItem if (priv->lines != NULL) { GSList *cur; - GtkGisGeometryLine *line; + GtkGisGeometry *line; GooCanvasItem *item = NULL; polygon_item = goo_canvas_group_new (NULL, NULL); cur = priv->lines; - line = (GtkGisGeometryLine *)cur->data; - while (cur != NULL) { - item = gtk_gis_geometry_draw (GTK_GIS_GEOMETRY (line)); + line = (GtkGisGeometry *)cur->data; + item = gtk_gis_geometry_draw (line); if (item != NULL) { diff --git a/src/geometrypolygon.h b/src/geometrypolygon.h index 641ac47..bfaf046 100644 --- a/src/geometrypolygon.h +++ b/src/geometrypolygon.h @@ -55,6 +55,7 @@ GtkGisGeometry *gtk_gis_geometry_polygon_new_from_line (GtkGisGeometryLine *line GtkGisGeometry *gtk_gis_geometry_polygon_new_from_list (GSList *points); void gtk_gis_geometry_polygon_add_line (GtkGisGeometryPolygon *polygon, GtkGisGeometryLine *line); +void gtk_gis_geometry_polygon_add_line_from_list (GtkGisGeometryPolygon *polygon, GSList *points); void gtk_gis_geometry_polygon_remove_line (GtkGisGeometryPolygon *polygon, GtkGisGeometryLine *line); diff --git a/src/gtkgis.c b/src/gtkgis.c index 8143477..e16e772 100644 --- a/src/gtkgis.c +++ b/src/gtkgis.c @@ -215,6 +215,13 @@ GtkWidget filename = xmlGetProp (cur, (const xmlChar *)"filename"); if (filename != NULL) { + if (!g_path_is_absolute (filename)) + { + filename = g_build_filename (g_get_current_dir (), + filename, + NULL); + } + layer_source = gtk_gis_layer_source_shp_new ((const gchar *)filename); } } @@ -273,7 +280,16 @@ GtkWidget { GtkWidget *gtkgis = NULL; - xmlDoc *xdoc = xmlParseFile (filename); + gchar *path = g_strdup (filename); + + if (!g_path_is_absolute (path)) + { + path = g_build_filename (g_get_current_dir (), + path, + NULL); + } + + xmlDoc *xdoc = xmlParseFile (path); if (xdoc != NULL) { gtkgis = gtk_gis_new_from_xml (xdoc); diff --git a/src/layersource.c b/src/layersource.c index 7ffdfc0..1c1b448 100644 --- a/src/layersource.c +++ b/src/layersource.c @@ -160,7 +160,7 @@ GList gint num_geometries; gint i_geometry; - OGRGeometryH poGeometryIns; + OGRGeometryH poGeometryInt; num_geometries = OGR_G_GetGeometryCount (poGeometry); @@ -172,21 +172,28 @@ GList GtkGisPoint *gpoint; - poGeometryIns = OGR_G_GetGeometryRef (poGeometry, i_geometry); + poGeometryInt = OGR_G_GetGeometryRef (poGeometry, i_geometry); - points = OGR_G_GetPointCount (poGeometryIns); + points = OGR_G_GetPointCount (poGeometryInt); for (point = 0; point < points; point++) { gpoint = g_malloc0 (sizeof (GtkGisPoint)); - gpoint->x = OGR_G_GetX (poGeometryIns, point); - gpoint->y = OGR_G_GetY (poGeometryIns, point); + gpoint->x = OGR_G_GetX (poGeometryInt, point); + gpoint->y = OGR_G_GetY (poGeometryInt, point); gpoints = g_slist_append (gpoints, gpoint); } - geometry = gtk_gis_geometry_polygon_new_from_list (gpoints); + if (i_geometry == 0) + { + geometry = gtk_gis_geometry_polygon_new_from_list (gpoints); + } + else + { + gtk_gis_geometry_polygon_add_line_from_list (GTK_GIS_GEOMETRY_POLYGON (geometry), gpoints); + } } } diff --git a/tests/test1.gtkgis b/tests/test1.gtkgis index f1bd6d9..e6aaea8 100644 --- a/tests/test1.gtkgis +++ b/tests/test1.gtkgis @@ -1,26 +1,26 @@ - + + - + - -- 2.49.0