private Collection <HotelInfomation> GetHotels() { Collection <HotelInfomation> hotels = new Collection <HotelInfomation>(); ShapeFileFeatureSource hotelFeatureSource = new ShapeFileFeatureSource(Server.MapPath("~/App_Data/Hotels.shp")); hotelFeatureSource.Open(); Collection <Feature> features = hotelFeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns); foreach (var item in features) { HotelInfomation hotel = new HotelInfomation(); hotel.FeatureId = item.Id; foreach (var keyValuePair in item.ColumnValues) { switch (keyValuePair.Key.ToLowerInvariant()) { case "name": hotel.Name = keyValuePair.Value; break; case "address": hotel.Address = keyValuePair.Value; break; case "rooms": hotel.Rooms = int.Parse(keyValuePair.Value, CultureInfo.InvariantCulture); break; default: break; } } hotels.Add(hotel); } return(hotels); }
private void DataJoinShapeFile() { var args = new UpdatingTaskProgressEventArgs(TaskState.Updating); ShapeFileFeatureSource currentSource = ShapeFileFeatureSource; if (!currentSource.IsOpen) { currentSource.Open(); } var index = 0; var count = currentSource.GetAllFeatures(ReturningColumnsType.AllColumns).Count; Collection <DbfColumn> includeColumns = new Collection <DbfColumn>(); RemoveUnduplicateColumn(IncludedColumnsList); foreach (var column in IncludedColumnsList) { DbfColumnType tmpDbfColumnType = DbfColumnType.Character; if (Enum.TryParse(column.TypeName, out tmpDbfColumnType)) { DbfColumn dbfColumn = new DbfColumn(column.ColumnName, tmpDbfColumnType, column.MaxLength, 0); includeColumns.Add(dbfColumn); } } ShapeFileType shapeFileType = GetShapeFileType(currentSource.GetAllFeatures(ReturningColumnsType.AllColumns).FirstOrDefault()); var projectionWkt = Proj4Projection.ConvertProj4ToPrj(DisplayProjectionParameters); var dataTable = DataJoinAdapter.ReadDataToDataGrid(CsvFilePath, Delimiter); var featureRows = dataTable.Rows; var helper = new ShapeFileHelper(shapeFileType, OutputPathFileName, includeColumns, projectionWkt); helper.ForEachFeatures(currentSource, (f, currentProgress, upperBound, percentage) => { try { bool canceled = false; if (f.GetWellKnownBinary() != null) { index++; try { var matchedDataRow = featureRows.Cast <DataRow>().FirstOrDefault(r => MatchConditions.All(tmpCondition => f.ColumnValues[tmpCondition.SelectedLayerColumn.ColumnName] == r[tmpCondition.SelectedDelimitedColumn.ColumnName].ToString())); if (matchedDataRow != null) { SetFeatureColumnValues(f, matchedDataRow, IncludedColumnsList, InvalidColumns); helper.Add(f); } else if (IsIncludeAllFeatures) { helper.Add(f); } if (UpdateProgress(OnUpdatingProgress, index, count)) { canceled = true; } } catch (Exception ex) { var errorEventArgs = new UpdatingTaskProgressEventArgs(TaskState.Error); errorEventArgs.Error = new ExceptionInfo(string.Format(CultureInfo.InvariantCulture, "Feature id: {0}, {1}" , f.Id, ex.Message) , ex.StackTrace , ex.Source); GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); errorEventArgs.Message = f.Id; OnUpdatingProgress(errorEventArgs); } } args = new UpdatingTaskProgressEventArgs(TaskState.Updating, percentage); args.Current = currentProgress; args.UpperBound = upperBound; OnUpdatingProgress(args); canceled = args.TaskState == TaskState.Canceled; return(canceled); } catch { return(false); } }); helper.Commit(); SavePrjFile(OutputPathFileName, DisplayProjectionParameters); }
/// <summary> /// Set up the map with the ThinkGeo Cloud Maps overlay and a feature layer containing Frisco zoning data /// </summary> protected override void OnAppearing() { base.OnAppearing(); // Create the background world maps using vector tiles requested from the ThinkGeo Cloud Service. ThinkGeoCloudVectorMapsOverlay thinkGeoCloudVectorMapsOverlay = new ThinkGeoCloudVectorMapsOverlay("9ap16imkD_V7fsvDW9I8r8ULxgAB50BX_BnafMEBcKg~", "vtVao9zAcOj00UlGcK7U-efLANfeJKzlPuDB9nw7Bp4K4UxU_PdRDg~~", ThinkGeoCloudVectorMapsMapType.Light); thinkGeoCloudVectorMapsOverlay.VectorTileCache = new FileVectorTileCache(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "cache"), "CloudMapsVector"); mapView.Overlays.Add(thinkGeoCloudVectorMapsOverlay); // Set the Map Unit to meters (used in Spherical Mercator) mapView.MapUnit = GeographyUnit.Meter; // Create a feature layer to hold and display the zoning data InMemoryFeatureLayer zoningLayer = new InMemoryFeatureLayer(); // Add a style to use to draw the Frisco zoning polygons zoningLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; zoningLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyle.CreateSimpleAreaStyle(GeoColor.FromArgb(50, GeoColors.MediumPurple), GeoColors.MediumPurple, 2); // Import the features from the Frisco zoning data shapefile ShapeFileFeatureSource zoningDataFeatureSource = new ShapeFileFeatureSource(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Data/Shapefile/Zoning.shp")); // Create a ProjectionConverter to convert the shapefile data from North Central Texas (2276) to Spherical Mercator (3857) ProjectionConverter projectionConverter = new ProjectionConverter(3857, 2276); // For this sample, we have to reproject the features before adding them to the feature layer // This is because the topological equality query often does not work when used on a feature layer with a ProjectionConverter, due to rounding issues between projections zoningDataFeatureSource.Open(); projectionConverter.Open(); foreach (Feature zoningFeature in zoningDataFeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns)) { Feature reprojectedFeature = projectionConverter.ConvertToInternalProjection(zoningFeature); zoningLayer.InternalFeatures.Add(reprojectedFeature); } zoningDataFeatureSource.Close(); projectionConverter.Close(); // Set the map extent to Frisco, TX //mapView.CurrentExtent = new RectangleShape(-10781137.28, 3917162.59, -10774579.34, 3911241.35); // Create a layer to hold the feature we will perform the spatial query against InMemoryFeatureLayer queryFeatureLayer = new InMemoryFeatureLayer(); queryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyle.CreateSimpleAreaStyle(GeoColor.FromArgb(75, GeoColors.LightRed), GeoColors.LightRed); queryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; // Create a layer to hold features found by the spatial query InMemoryFeatureLayer highlightedFeaturesLayer = new InMemoryFeatureLayer(); highlightedFeaturesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyle.CreateSimpleAreaStyle(GeoColor.FromArgb(90, GeoColors.MidnightBlue), GeoColors.MidnightBlue); highlightedFeaturesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; // Add each feature layer to it's own overlay // We do this so we can control and refresh/redraw each layer individually LayerOverlay layerOverlay = new LayerOverlay(); layerOverlay.Layers.Add("Frisco Zoning", zoningLayer); layerOverlay.Layers.Add("Query Feature", queryFeatureLayer); layerOverlay.Layers.Add("Highlighted Features", highlightedFeaturesLayer); mapView.Overlays.Add("Layer Overlay", layerOverlay); // Create a sample shape using vertices from an existing feature, to ensure that it is touching other features zoningLayer.Open(); MultipolygonShape firstFeatureShape = (MultipolygonShape)zoningLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.NoColumns).First().GetShape(); // Get vertices from an existing feature var vertices = firstFeatureShape.Polygons.First().OuterRing.Vertices; // Create a new feature using a subset of those vertices MultipolygonShape sampleShape = new MultipolygonShape(new Collection <PolygonShape> { new PolygonShape(new RingShape(new Collection <Vertex> { vertices[0], vertices[1], vertices[2] })) }); queryFeatureLayer.InternalFeatures.Add(new Feature(sampleShape)); zoningLayer.Close(); GetFeaturesTouching(sampleShape); // Set the map extent to the sample shape mapView.CurrentExtent = new RectangleShape(-10778499.3056056, 3920951.91647677, -10774534.1347853, 3917536.13679426); mapView.Refresh(); }