From b1fee1f209af6ce3f34030c8a4820903ffac161d Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Mon, 6 Jul 2009 17:43:27 +0200 Subject: [PATCH] Fixed libgtkgis.pc.in to include goocanvas and gdal. Fixed tests/from_xml.c on #include. Added GtkGisLayerSource::set_max_extent. Fixed coordinates for multiple layers. Reduced default geometries line-width to 0.5 instead of 1.0. Changed goocanvas item type from rect to ellipse for GtkGisGeometryPoint. --- libgtkgis.pc.in | 6 +++--- src/geometryline.c | 2 +- src/geometrypoint.c | 11 ++++++----- src/gtkgis.c | 1 + src/layer.c | 4 +--- src/layer.h | 1 + src/layersource.c | 42 +++++++++++++++++++++++++++++++++++------- src/layersource.h | 3 +++ tests/Makefile.am | 4 +++- tests/README | 6 ++++++ tests/from_xml.c | 2 +- tests/test1.gtkgis | 8 ++++---- 12 files changed, 65 insertions(+), 25 deletions(-) create mode 100644 tests/README diff --git a/libgtkgis.pc.in b/libgtkgis.pc.in index e2fbbbc..0c4b67f 100644 --- a/libgtkgis.pc.in +++ b/libgtkgis.pc.in @@ -6,6 +6,6 @@ includedir=@includedir@ Name: @PACKAGE_NAME@ Description: A Gtk+ widget to embed base GIS functionalities into applications. Version: @PACKAGE_VERSION@ -Requires: gtk+-2.0 -Libs: -L${libdir} -lgtkgis -Cflags: -I${includedir} +Requires: gtk+-2.0 goocanvas +Libs: -L${libdir} @GDAL_LIBS@ -lgtkgis +Cflags: @GDAL_CFLAGS@ -I${includedir}/gtkgis diff --git a/src/geometryline.c b/src/geometryline.c index 8dae4e0..ba25a7c 100644 --- a/src/geometryline.c +++ b/src/geometryline.c @@ -216,7 +216,7 @@ static GooCanvasItem path = convert_comma_to_dot (path); item = goo_canvas_path_new (NULL, path, - "line-width", 1.0 / scale->xy, + "line-width", 0.5 / scale->xy, NULL); } diff --git a/src/geometrypoint.c b/src/geometrypoint.c index 7336fd2..fc4f22f 100644 --- a/src/geometrypoint.c +++ b/src/geometrypoint.c @@ -156,11 +156,12 @@ GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point, GtkGisScale * if (priv->point != NULL) { - item = goo_canvas_rect_new (NULL, - priv->point->x, priv->point->y, - 1 / scale->x, 1 / scale->y, - "line-width", 1.0 / scale->xy, - NULL); + item = goo_canvas_ellipse_new (NULL, + priv->point->x, priv->point->y, + 0.5 / scale->x, 0.5 / scale->y, + "line-width", 0.5 / scale->xy, + "fill-color", "black", + NULL); } return item; diff --git a/src/gtkgis.c b/src/gtkgis.c index 34f8b5e..64d6ecc 100644 --- a/src/gtkgis.c +++ b/src/gtkgis.c @@ -241,6 +241,7 @@ GtkWidget { layer = gtk_gis_layer_new_from_source (layer_source, layer_name); gtk_gis_add_layer (GTK_GIS (gtkgis), layer); + gtk_gis_layer_source_set_max_extent (layer_source, priv->extent); } cur = xml_source_spec; diff --git a/src/layer.c b/src/layer.c index 0caa313..3d01132 100644 --- a/src/layer.c +++ b/src/layer.c @@ -129,8 +129,6 @@ GtkGisLayer if (type >= 0) { layer = gtk_gis_layer_new (source, name, type); - - gtk_gis_layer_fill_from_source (layer); } return layer; @@ -281,7 +279,7 @@ gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale) priv = GTK_GIS_LAYER_GET_PRIVATE (layer); - g_return_if_fail (priv->geometries != NULL); + gtk_gis_layer_fill_from_source (layer); priv->layer_item = goo_canvas_group_new (root, NULL); diff --git a/src/layer.h b/src/layer.h index a052795..84224b6 100644 --- a/src/layer.h +++ b/src/layer.h @@ -25,6 +25,7 @@ #include +#include "commons.h" #include "geometry.h" #include "layersource.h" diff --git a/src/layersource.c b/src/layersource.c index 258f874..3f8fb2a 100644 --- a/src/layersource.c +++ b/src/layersource.c @@ -53,6 +53,8 @@ typedef struct _GtkGisLayerSourcePrivate GtkGisLayerSourcePrivate; struct _GtkGisLayerSourcePrivate { OGRDataSourceH datasource; + + GtkGisLayerExtent *max_extent; }; G_DEFINE_TYPE (GtkGisLayerSource, gtk_gis_layer_source, G_TYPE_OBJECT) @@ -83,6 +85,8 @@ gtk_gis_layer_source_set_ogr_datasource (GtkGisLayerSource *source, GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source); priv->datasource = datasource; + + priv->max_extent = NULL; } @@ -104,11 +108,11 @@ GList OGRLayerH layer; OGRFeatureH feature; - GtkGisLayerExtent extent; - OGRGeometryH poGeometry; GtkGisGeometry *geometry; + gdouble fixy; + GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source); g_return_if_fail (priv->datasource != NULL); @@ -117,10 +121,17 @@ GList g_return_if_fail (layer != NULL); - extent = gtk_gis_layer_source_get_layer_extent (source, name); - OGR_L_ResetReading (layer); + /*if (priv->max_extent == NULL) + { + fixy = 0.0f; + } + else + {*/ + fixy = priv->max_extent->max_y + priv->max_extent->min_y; + //} + while ((feature = OGR_L_GetNextFeature (layer)) != NULL) { poGeometry = OGR_F_GetGeometryRef (feature); @@ -131,7 +142,7 @@ GList GtkGisPoint gpoint; gpoint.x = OGR_G_GetX (poGeometry, 0); - gpoint.y = extent.max_y - OGR_G_GetY (poGeometry, 0) + extent.min_y; + gpoint.y = fixy - OGR_G_GetY (poGeometry, 0); geometry = gtk_gis_geometry_point_new (gpoint); } @@ -151,7 +162,7 @@ GList gpoint = g_malloc0 (sizeof (GtkGisPoint)); gpoint->x = OGR_G_GetX (poGeometry, point); - gpoint->y = extent.max_y - OGR_G_GetY (poGeometry, point) + extent.min_y; + gpoint->y = fixy - OGR_G_GetY (poGeometry, point); gpoints = g_slist_append (gpoints, gpoint); } @@ -185,7 +196,7 @@ GList gpoint = g_malloc0 (sizeof (GtkGisPoint)); gpoint->x = OGR_G_GetX (poGeometryInt, point); - gpoint->y = extent.max_y - OGR_G_GetY (poGeometryInt, point) + extent.min_y; + gpoint->y = fixy - OGR_G_GetY (poGeometryInt, point); gpoints = g_slist_append (gpoints, gpoint); } @@ -283,6 +294,23 @@ gtk_gis_layer_source_get_layer_extent (GtkGisLayerSource *source, return extent; } +void +gtk_gis_layer_source_set_max_extent (GtkGisLayerSource *source, + GtkGisLayerExtent *extent) +{ + GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source); + + if (priv->max_extent == NULL) + { + priv->max_extent = g_malloc0 (sizeof (GtkGisLayerExtent)); + } + + priv->max_extent->min_x = extent->min_x; + priv->max_extent->max_x = extent->max_x; + priv->max_extent->min_y = extent->min_y; + priv->max_extent->max_y = extent->max_y; +} + static void gtk_gis_layer_source_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { diff --git a/src/layersource.h b/src/layersource.h index 76e2d49..d325eb9 100644 --- a/src/layersource.h +++ b/src/layersource.h @@ -68,6 +68,9 @@ GtkGisLayerGeometryType gtk_gis_layer_source_get_layer_geometry_type (GtkGisLaye GtkGisLayerExtent gtk_gis_layer_source_get_layer_extent (GtkGisLayerSource *source, const gchar *name); +void gtk_gis_layer_source_set_max_extent (GtkGisLayerSource *source, + GtkGisLayerExtent *extent); + G_END_DECLS diff --git a/tests/Makefile.am b/tests/Makefile.am index 27d0331..fc4dc10 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -13,4 +13,6 @@ LDADD = $(libgtkgis) noinst_PROGRAMS = from_xml -EXTRA_DIST = test1.gtkgis +EXTRA_DIST = \ + README \ + test1.gtkgis diff --git a/tests/README b/tests/README new file mode 100644 index 0000000..d3b149f --- /dev/null +++ b/tests/README @@ -0,0 +1,6 @@ +You can find some sample data on + +http://www.qgis.org/en/download/sample-data.html + +then change accordingly test files *.gtkgis or create new ones based on +../data/gtkgis.dtd. diff --git a/tests/from_xml.c b/tests/from_xml.c index 4dd576c..610ae64 100644 --- a/tests/from_xml.c +++ b/tests/from_xml.c @@ -1,4 +1,4 @@ -#include +#include int main (int argc, char *argv[]) diff --git a/tests/test1.gtkgis b/tests/test1.gtkgis index 090eb87..3a39de7 100644 --- a/tests/test1.gtkgis +++ b/tests/test1.gtkgis @@ -2,25 +2,25 @@ - + - + - + - + -- 2.49.0