// NPGSQL EXCEPTION - BAD GEOMETRY FORMATING IN THE RESULTING QUERY && TABLE NAMES MUST BE ALTERED NOT TO CONTAIN "" private void GetGeometryIntersections(IGeometry geometry) { SharpMap.Data.Providers.PostGIS postGisProv = new SharpMap.Data.Providers.PostGIS(Constants.connStr, _activeLayer, Constants.geomName, Constants.idName); SharpMap.Data.FeatureDataSet fds = new SharpMap.Data.FeatureDataSet(); postGisProv.Open(); postGisProv.ExecuteIntersectionQuery(geometry, fds); postGisProv.Close(); //System.Windows.Forms.MessageBox.Show(fds.Tables[0].Rows.Count.ToString()); _view.DataGridView = fds.Tables[0]; }
public void OnQueryLayer(string query, System.Drawing.Color resultColor) { // Create the postGis provider object, and init it's query property with the passed query SharpMap.Data.Providers.PostGIS postGisProv = new SharpMap.Data.Providers.PostGIS(Constants.connStr, _activeLayer, Constants.geomName, Constants.idName) { DefinitionQuery = query }; SharpMap.Rendering.Thematics.ITheme theme = null; System.Drawing.Brush queryResultBrush = new System.Drawing.SolidBrush(resultColor); // Create a theme based on the active layer if (_activeLayer == Constants.roadsTable) { System.Drawing.Pen queryResultPen = new System.Drawing.Pen(queryResultBrush); theme = new SharpMap.Rendering.Thematics.CustomTheme((SharpMap.Data.FeatureDataRow fdr) => { return(new VectorStyle() { Line = queryResultPen }); }); } else if (_activeLayer == Constants.nrTable) { theme = new SharpMap.Rendering.Thematics.CustomTheme((SharpMap.Data.FeatureDataRow fdr) => { return(new VectorStyle() { PointColor = queryResultBrush, PointSize = 3f }); }); } else { theme = new SharpMap.Rendering.Thematics.CustomTheme((SharpMap.Data.FeatureDataRow fdr) => { return(new VectorStyle() { Fill = queryResultBrush }); }); } // Create the resulting vector layer object for query result, and set the created theme VectorLayer resultingLayer = new VectorLayer(Constants.queryLayerName) { DataSource = postGisProv, Theme = theme }; // Create label of the results LabelLayer resultingLabel = new LabelLayer(Constants.queryLabelName) { DataSource = resultingLayer.DataSource, Enabled = true, LabelColumn = "name", MaxVisible = 0.3f }; try { // NPGSQL exception handle ruins the map by returning an empty layer // Getting an envelope when query is invalid triggers an exception SharpMap.Data.FeatureDataSet fds = new SharpMap.Data.FeatureDataSet(); postGisProv.Open(); Envelope envelope = resultingLayer.Envelope; // <----- Exception postGisProv.ExecuteIntersectionQuery(envelope, fds); postGisProv.Close(); // Remove the previous query result if it exists OnRemoveLayer(Constants.queryLayerName); OnRemoveLayer(Constants.queryLabelName); // Add the results to the map _view.AddLayer(resultingLayer); _view.AddLayer(resultingLabel); _view.DataGridView = fds.Tables[0]; } catch (System.Exception e) { System.Console.Write(e.Message); return; } }