/// <summary> /// Gets FeatureInfo. /// </summary> /// <param name="map">The map to create the feature info from.</param> /// <param name="requestedLayers">The layers to create the feature info for.</param> /// <param name="x">The x-ordinate.</param> /// <param name="y">The y-ordinate.</param> /// <param name="featureCount">The max number of features retrieved.</param> /// <param name="cqlFilter">The CQL Filter string.</param> /// <param name="pixelSensitivity">The sensitivity to use when querying data.</param> /// <param name="intersectDelegate">A <see cref="WmsServer.InterSectDelegate"/> to filter data.</param> /// <returns>Text string with featureinfo results.</returns> protected abstract AbstractGetFeatureInfoResponse CreateFeatureInfo(Map map, IEnumerable <string> requestedLayers, float x, float y, int featureCount, string cqlFilter, int pixelSensitivity, WmsServer.InterSectDelegate intersectDelegate);
protected override AbstractGetFeatureInfoResponse CreateFeatureInfo(Map map, IEnumerable <string> requestedLayers, float x, float y, int featureCount, string cqlFilter, int pixelSensitivity, WmsServer.InterSectDelegate intersectDelegate) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("GetFeatureInfo results:{0}", NewLine); foreach (string requestLayer in requestedLayers) { ICanQueryLayer layer = GetQueryLayer(map, requestLayer); IFeatureCollectionSet fds; if (!TryGetData(map, x, y, pixelSensitivity, intersectDelegate, layer, cqlFilter, out fds)) { sb.AppendFormat("Search returned no results on layer: {0}{1}", requestLayer, NewLine); continue; } sb.AppendFormat("Layer: '{0}'{1}", requestLayer, NewLine); sb.AppendFormat("Featureinfo:{0}", NewLine); var table = fds[0]; string rowsText = GetRowsText(table, featureCount); sb.Append(rowsText).Append(NewLine); } return(new GetFeatureInfoResponsePlain(sb.ToString())); }
public GetFeatureInfoParams(int pixelSensitivity, WmsServer.InterSectDelegate intersectDelegate, Encoding encoding) { _pixelSensitivity = pixelSensitivity; _intersectDelegate = intersectDelegate; _encoding = encoding; }
public GetFeatureInfoParams(int pixelSensitivity, WmsServer.InterSectDelegate intersectDelegate, Encoding encoding) { _pixelSensitivity = pixelSensitivity; _intersectDelegate = intersectDelegate; _encoding = encoding; }
/// <summary> /// Check if the layer can be queried and retrieve data, if there is any. /// </summary> protected bool TryGetData(Map map, float x, float y, int pixelSensitivity, WmsServer.InterSectDelegate intersectDelegate, ICanQueryLayer queryLayer, string cqlFilter, out IFeatureCollectionSet fds) { if (!queryLayer.IsQueryEnabled) { fds = null; return(false); } float queryBoxMinX = x - pixelSensitivity; float queryBoxMinY = y - pixelSensitivity; float queryBoxMaxX = x + pixelSensitivity; float queryBoxMaxY = y + pixelSensitivity; Coordinate minXY = map.ImageToWorld(new PointF(queryBoxMinX, queryBoxMinY)); Coordinate maxXY = map.ImageToWorld(new PointF(queryBoxMaxX, queryBoxMaxY)); Envelope queryBox = new Envelope(minXY, maxXY); fds = new FeatureCollectionSet(); queryLayer.ExecuteIntersectionQuery(queryBox, fds); if (fds.Count == 0) { return(false); } var table = fds[0]; if (intersectDelegate != null) { fds.Remove(table); fds.Add(intersectDelegate(table, queryBox)); table = fds[0]; } // filter the rows with the CQLFilter if one is provided if (cqlFilter != null) { var toKeep = table.Clone(); foreach (var feature in table) { if (CqlFilter(feature, cqlFilter)) { toKeep.Add(feature); } } fds.Remove(table); fds.Add(toKeep); } return(fds[0].Count > 0); }
protected override AbstractGetFeatureInfoResponse CreateFeatureInfo(Map map, IEnumerable <string> requestedLayers, float x, float y, int featureCount, string cqlFilter, int pixelSensitivity, WmsServer.InterSectDelegate intersectDelegate) { List <GeoJSON> items = new List <GeoJSON>(); foreach (string requestLayer in requestedLayers) { ICanQueryLayer queryLayer = GetQueryLayer(map, requestLayer); FeatureDataSet fds; if (!TryGetData(map, x, y, pixelSensitivity, intersectDelegate, queryLayer, cqlFilter, out fds)) { continue; } IEnumerable <GeoJSON> data = GeoJSONHelper.GetData(fds); // reproject geometries if needed IMathTransform transform = null; if (queryLayer is VectorLayer) { ICoordinateTransformation transformation = (queryLayer as VectorLayer).CoordinateTransformation; if (transformation != null) { transform = transformation.MathTransform; } } if (transform != null) { #if DotSpatialProjections throw new NotImplementedException(); #else data = data.Select(d => { IGeometry converted = GeometryTransform.TransformGeometry(d.Geometry, transform, map.Factory); d.SetGeometry(converted); return(d); }); #endif } items.AddRange(data); } StringWriter sb = new StringWriter(); GeoJSONWriter.Write(items, sb); return(new GetFeatureInfoResponseJson(sb.ToString())); }
/// <summary> /// Check if the layer can be queried and retrieve data, if there is any. /// </summary> protected bool TryGetData(Map map, float x, float y, int pixelSensitivity, WmsServer.InterSectDelegate intersectDelegate, ICanQueryLayer queryLayer, string cqlFilter, out FeatureDataSet fds) { if (!queryLayer.IsQueryEnabled) { fds = null; return false; } float queryBoxMinX = x - pixelSensitivity; float queryBoxMinY = y - pixelSensitivity; float queryBoxMaxX = x + pixelSensitivity; float queryBoxMaxY = y + pixelSensitivity; Coordinate minXY = map.ImageToWorld(new PointF(queryBoxMinX, queryBoxMinY)); Coordinate maxXY = map.ImageToWorld(new PointF(queryBoxMaxX, queryBoxMaxY)); Envelope queryBox = new Envelope(minXY, maxXY); fds = new FeatureDataSet(); queryLayer.ExecuteIntersectionQuery(queryBox, fds); FeatureTableCollection tables = fds.Tables; FeatureDataTable table = tables[0]; if (intersectDelegate != null) tables[0] = intersectDelegate(table, queryBox); // filter the rows with the CQLFilter if one is provided if (cqlFilter != null) { DataRowCollection rows = table.Rows; for (int i = rows.Count - 1; i >= 0; i--) { FeatureDataRow row = (FeatureDataRow)rows[i]; bool b = CqlFilter(row, cqlFilter); if (!b) rows.RemoveAt(i); } } bool res = tables.Count > 0 && table.Rows.Count > 0; return res; }
protected override AbstractGetFeatureInfoResponse CreateFeatureInfo(Map map, IEnumerable <string> requestedLayers, float x, float y, int featureCount, string cqlFilter, int pixelSensitivity, WmsServer.InterSectDelegate intersectDelegate) { StringBuilder sb = new StringBuilder(); foreach (string requestLayer in requestedLayers) { ICanQueryLayer layer = GetQueryLayer(map, requestLayer); IFeatureCollectionSet fds; if (!TryGetData(map, x, y, pixelSensitivity, intersectDelegate, layer, cqlFilter, out fds)) { continue; } var table = fds[0]; var attributeDefinition = table[0].Factory.AttributesDefinition; StringBuilder sbTable = new StringBuilder(); sbTable.AppendFormat("<tr>{0}", NewLine); foreach (IFeatureAttributeDefinition col in attributeDefinition) { sbTable.AppendFormat("<th>{0}</th>{1}", col.AttributeName, NewLine); } sbTable.AppendFormat("</tr>{0}", NewLine); string rowsText = GetRowsText(table, featureCount); sbTable.Append(rowsText); string tpl = TableTemplate. Replace("{{LAYER_NAME}}", requestLayer). Replace("{{LAYER_TABLE}}", sbTable.ToString()); sb.AppendFormat("{0}\n{1}\n", tpl, "<br />"); } string html = HtmlTemplate.Replace("{{HTML_BODY}}", sb.ToString()); return(new GetFeatureInfoResponseHtml(html)); }
public GetFeatureInfoParams(int pixelSensitivity, WmsServer.InterSectDelegate intersectDelegate) { if (intersectDelegate == null) /* can be null */ } {
public GetFeatureInfo(HandlerParams @params, GetFeatureInfoParams infoParams) : base(@params) { this.pixelSensitivity = infoParams.PixelSensitivity; this.intersectDelegate = infoParams.IntersectDelegate; }
public GetFeatureInfo(HandlerParams @params, GetFeatureInfoParams infoParams) : base(@params) { this.pixelSensitivity = infoParams.PixelSensitivity; this.intersectDelegate = infoParams.IntersectDelegate; }