]> saetta.ns0.it Git - libgtkgis/commitdiff
Fixed bug on GtkGisGeomtryPolygon with multiple geometries.
authorAndrea Zagli <azagli@libero.it>
Sat, 4 Jul 2009 14:36:48 +0000 (16:36 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 4 Jul 2009 14:36:48 +0000 (16:36 +0200)
Added GtkGisGeometry::add_line_from_list.
Added support for relative filename path.

src/geometrypolygon.c
src/geometrypolygon.h
src/gtkgis.c
src/layersource.c
tests/test1.gtkgis

index 27af4ab9af4f554329596f6fff6f0641a8a1c492..188720760752e1a480c0a17f9bb3102fe3761ffc 100644 (file)
@@ -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)
                                                {
index 641ac47107e3fe4877b91ab1d6cc98b065ebfbbf..bfaf046745c6ebfc8baa44f6d4024854ece7053d 100644 (file)
@@ -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);
 
 
index 81434779f57132218ddca15c5dc711a969853c4d..e16e7721795f9c578cd2c3bff27e010e9c2530cb 100644 (file)
@@ -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);
index 7ffdfc0be6ac135005d93d2fd6f0bd9ff90885de..1c1b448108f4c105d9b288b386029046d29e0cda 100644 (file)
@@ -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);
+                                                               }
                                                }
                                }
 
index f1bd6d99928671fc42d12bd6e5a2127abf68186b..e6aaea8c9a84f234f9bb3b064ec2aa212c910061 100644 (file)
@@ -1,26 +1,26 @@
 <gtkgis>
 
-       <!--<layer name="alaska">
+       <layer name="alaska">
                <source>
-                       <shape filename="/home/andreaz/files/c/libgtkgis/tests/samples/alaska.shp" />
+                       <shape filename="tests/samples/alaska.shp" />
                </source>
-       </layer>-->
+       </layer>
 
        <!--<layer name="airports">
                <source>
-                       <shape filename="/home/andreaz/files/c/libgtkgis/tests/samples/airports.shp" />
+                       <shape filename="tests/samples/airports.shp" />
                </source>
-       </layer>-->
+       </layer>
 
        <layer name="railroads">
                <source>
-                       <shape filename="/home/andreaz/files/c/libgtkgis/tests/samples/railroads.shp" />
+                       <shape filename="tests/samples/railroads.shp" />
                </source>
        </layer>
 
-       <!--<layer name="rivers">
+       <layer name="rivers">
                <source>
-                       <shape filename="/home/andreaz/files/c/libgtkgis/tests/samples/rivers.shp" />
+                       <shape filename="tests/samples/rivers.shp" />
                </source>
        </layer>-->