/// <summary>
        /// Get a MultiFeatureCollection containing features in all layers falling into the tolerance of the point.
        /// </summary>
        /// <param name="points">points array</param>
        /// <param name="pixelTolerance">pixel tolerance used when searching</param>
        /// <returns>Returns a MultiResultSetFeatureCollection object</returns>
        protected MultiResultSetFeatureCollection RetrieveInfo(Point[] points, int pixelTolerance)
        {
            if (points.Length != 1)
            {
                return(null);
            }

            MapControlModel model = MapControlModel.GetModelFromSession();

            //get map object from map model
            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);

            if (map == null)
            {
                return(null);
            }

            //creat a layer filter to include normal visible layers for searching
            IMapLayerFilter layerFilter = MapLayerFilterFactory.FilterForTools(
                map, MapLayerFilterFactory.FilterByLayerType(LayerType.Normal), MapLayerFilterFactory.FilterVisibleLayers(true),
                "MapInfo.Tools.MapToolsDefault.SelectLayers", null);

            ITableEnumerator tableEnum = map.Layers.GetTableEnumerator(layerFilter);

            //return if there is no valid layer to search
            if (tableEnum == null)
            {
                return(null);
            }

            System.Drawing.Point center = points[0];

            //create a SearchInfo with a point and tolerance
            SearchInfo si = MapInfo.Mapping.SearchInfoFactory.SearchNearest(map, center, pixelTolerance);

            (si.SearchResultProcessor as ClosestSearchResultProcessor).Options = ClosestSearchOptions.StopAtFirstMatch;
            //retrieve all columns
            si.QueryDefinition.Columns = null;

            MapInfo.Geometry.Distance d = MapInfo.Mapping.SearchInfoFactory.ScreenToMapDistance(map, pixelTolerance);
            (si.SearchResultProcessor as ClosestSearchResultProcessor).DistanceUnit = d.Unit;
            (si.SearchResultProcessor as ClosestSearchResultProcessor).MaxDistance  = d.Value;


            //do search
            MultiResultSetFeatureCollection mrfc = MapInfo.Engine.Session.Current.Catalog.Search(tableEnum, si);

            return(mrfc);
        }
示例#2
0
 private GeocodeConstraints BuildConstraints()
 {
     GeocodeConstraints result = new GeocodeConstraints();
     result.CloseMatchesOnly = cbCloseMatchesOnly.Checked;
     result.FallbackToPostal = cbFallbackPostal.Checked;
     result.FallbackToGeographic = cbFallbackGeographic.Checked;
     result.MustMatchAddressNumber = cbMatchAddrNumber.Checked;
     result.MustMatchMainAddress = cbMatchMainAddr.Checked;
     result.MustMatchInput = cbMatchInput.Checked;
     result.MustMatchMunicipality = cbMatchCity.Checked;
     result.MustMatchCountrySubdivision = cbMatchState.Checked;
     result.MustMatchPostalCode = cbMatchPostal.Checked;
       result.MustMatchCountry = cbMatchCountry.Checked;
       result.MaxCandidates = (int) maxCandidates.Value;
       result.MaxRanges = (int) maxRanges.Value;
       result.MaxRangeUnits = (int) maxRangeUnits.Value;
       System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");
       MapInfo.Geometry.Distance offset = new MapInfo.Geometry.Distance(25.0, MapInfo.Geometry.DistanceUnit.Foot);
       offset.Value = Convert.ToDouble(streetOffset.Text, culture);
       offset.Unit = MapInfo.Geometry.CoordSys.DistanceUnitFromKeyword(streetOffsetUnits.Text);
       result.OffsetFromStreet = offset;
     offset.Value = Convert.ToDouble(cornerOffset.Text, culture);
     offset.Unit = MapInfo.Geometry.CoordSys.DistanceUnitFromKeyword(cornerOffsetUnits.Text);
     result.OffsetFromCorner = offset;
       result.GeocodeType = (MapInfo.Geocoding.GeocodeType) Enum.Parse(typeof(MapInfo.Geocoding.GeocodeType), geocodeType.Text);
       result.DictionaryUsage = (MapInfo.Geocoding.DictionaryUsage) Enum.Parse(typeof(MapInfo.Geocoding.DictionaryUsage), dictionaryUsage.Text);
     return result;
 }