public static Map InitializeMap() { HttpContext context = HttpContext.Current; Map map = new Map(new Size(1, 1)); foreach (string layer in layers.Keys) { string format = String.Format("~/App_Data/nyc/{0}.shp", layer); string path = context.Server.MapPath(format); if (!File.Exists(path)) throw new FileNotFoundException("file not found", path); LayerData data = layers[layer]; ShapeFile dataSource = new ShapeFile(path, true) { SRID = 900913 }; VectorLayer item = new VectorLayer(layer, dataSource) { CoordinateTransformation = data.Transformation, Style = (VectorStyle)data.Style, SmoothingMode = SmoothingMode.AntiAlias }; map.Layers.Add(item); // LabelLayer labels = CreateLabelLayer(item, data.LabelColumn); // map.Layers.Add(labels); } return map; }
public static IEnumerable <ILayer> CreateLayers(string fileName) { var layers = new List <ILayer>(); //var countrySource = new ShapeFile(GetAppDir() + "\\GeoData\\World\\countries.shp", true) { CRS = "EPSG:3785" }; //var citySource = new ShapeFile(GetAppDir() + "\\GeoData\\World\\cities.shp", true) { CRS = "EPSG:3785" }; //layers.Add(new RasterizingLayer(CreateCountryLayer(countrySource))); //layers.Add(new RasterizingLayer(CreateCityLayer(citySource))); //layers.Add(new RasterizingLayer(CreateCountryLabelLayer(countrySource))); //layers.Add(new RasterizingLayer(CreateCityLabelLayer(citySource))); var source = new ShapeFile(fileName, false) { CRS = "EPSG:3785" }; layers.Add(new RasterizingLayer(new Layer { Name = "Shapefile", DataSource = source, Style = new ThemeStyle(f => new VectorStyle { Line = new Pen(Color.Black) }), FetchingPostponedInMilliseconds = 100, Overscan = 1.5 }, rasterizer: new Mapsui.Rendering.Gdi.MapRenderer() { HighQuality = true }, delayBeforeRasterize: 300, overscanRatio: 3)); return(layers); }
public static TripFile GetDefaultTripFile() { if (_defaultTripFile != null) { return(_defaultTripFile); } _defaultTripFile = new TripFile("Trips/burlington.trp"); var shpFile = new ShapeFile("Trips/burlington.shp"); var stpFile = new StopFile("Trips/burlington.stp"); var tmsFile = new TripTimeFile("Trips/burlington.tms"); var rutFile = GetDefaultRouteFile(); // Link files var watch = Stopwatch.StartNew(); // debug runtime watch _defaultTripFile.BindRoutes(rutFile); _defaultTripFile.BindShapes(shpFile); _defaultTripFile.BindTripTimes(tmsFile); _defaultTripFile.BindStops(stpFile); Console.WriteLine("Bind Time: " + watch.ElapsedMilliseconds); watch.Reset(); watch.Start(); _defaultTripFile.MixInStops(); Console.WriteLine("Mixin Time: " + watch.ElapsedMilliseconds); return(_defaultTripFile); }
public static Map PolyMaps() { HttpContext context = HttpContext.Current; Map map = new Map(new Size(1, 1)); foreach (string layer in layers.Keys) { string format = String.Format("~/App_Data/nyc/{0}.shp", layer); string path = context.Server.MapPath(format); if (!File.Exists(path)) { throw new FileNotFoundException("file not found", path); } LayerData data = layers[layer]; ShapeFile dataSource = new ShapeFile(path, true) { SRID = 4326 }; VectorLayer item = new VectorLayer(layer, dataSource) { Style = (VectorStyle)data.Style, SmoothingMode = SmoothingMode.AntiAlias }; map.Layers.Add(item); } return(map); }
public static Map OpenLayers() { ICoordinateTransformation transformation = LatLonToGoogle(); HttpContext context = HttpContext.Current; Map map = new Map(new Size(1, 1)); IDictionary<string, LayerData> dict = Nyc; foreach (string layer in dict.Keys) { string format = String.Format("~/App_Data/nyc/{0}.shp", layer); string path = context.Server.MapPath(format); if (!File.Exists(path)) throw new FileNotFoundException("file not found", path); LayerData data = dict[layer]; ShapeFile dataSource = new ShapeFile(path, true) { SRID = 900913 }; VectorLayer item = new VectorLayer(layer, dataSource) { Style = (VectorStyle)data.Style, SmoothingMode = SmoothingMode.AntiAlias, CoordinateTransformation = transformation }; map.Layers.Add(item); } return map; }
private void toolStripButton1_Click(object sender, EventArgs e) { MogreApp.setLocations(prj.getMogreLocations()); SetupMogre(); Mogre.SceneManager sm = app.SceneManager; foreach (MogreGis.FilterGraph graph in prj.getFilterGraphs()) { foreach (osgGISProjects.Source source in prj.getSources()) { if (Path.GetExtension(source.getURI()) != ".shp") { throw new NotImplementedException(); } if (source.getName() == graph.getName()) { MogreGis.FilterEnv env = null; MogreGis.FeatureList featureList = null; FeatureDataSet ds = new FeatureDataSet(); source.DataSource.Open(); source.DataSource.ExecuteIntersectionQuery(source.DataSource.GetExtents(), ds); source.DataSource.Close(); FeatureDataTable features = (FeatureDataTable)ds.Tables[0]; featureList = MogreGis.Feature.DataTableToList(features); foreach (Script script in prj.getScripts()) { Registry.instance().GetEngine("Python").run(script); } foreach (Feature feature in featureList) { SharpMapSpatialReferenceFactory smsrf = new SharpMapSpatialReferenceFactory(); ShapeFile shp = new ShapeFile(source.getURI()); shp.Open(); SharpMapSpatialReference sr; sr = (SharpMapSpatialReference)smsrf.createSRSfromWKT(shp.CoordinateSystem.WKT); feature.getGeometry().SpatialReference = sr; } env = new MogreGis.FilterEnv(sm, "env" + graph.getName()); env.setScriptEngine(Registry.instance().GetEngine("Python")); foreach (MogreGis.Filter filter in graph.getFilters()) { if (filter is MogreGis.FragmentFilter) { (filter as MogreGis.FragmentFilter).process(featureList, env); } if (filter is MogreGis.FeatureFilter) { featureList = (filter as MogreGis.FeatureFilter).process(featureList, env); } } } } } app.getRoot().StartRendering(); }
public static Map Spherical() { ICoordinateTransformation transformation = ProjHelper.LatLonToGoogle(); HttpContext context = HttpContext.Current; Map map = new Map(new Size(1, 1)); IDictionary <string, LayerData> dict = Nyc; foreach (string layer in dict.Keys) { string format = String.Format("~/App_Data/{0}", layer); string path = context.Server.MapPath(format); if (!File.Exists(path)) { throw new FileNotFoundException("file not found", path); } string name = Path.GetFileNameWithoutExtension(layer); LayerData data = dict[layer]; ShapeFile source = new ShapeFile(path, true, new WebCacheUtility()); VectorLayer item = new VectorLayer(name, source) { SRID = 4326, TargetSRID = 900913, CoordinateTransformation = transformation, Style = (VectorStyle)data.Style, SmoothingMode = SmoothingMode.AntiAlias }; map.Layers.Add(item); } return(map); }
public void DebugLoadFileShape(string shapeFilePath) { var output = @"G:\NickProd\Farming Simulator 19\Temp"; var gameDirectory = GamePaths.GetGamePath(FarmSimulatorVersion.FarmingSimulator2017); var realtive = Path.GetRelativePath(gameDirectory, shapeFilePath); var shapeFile = new ShapeFile(shapeFilePath); var index = 0; try { shapeFile.ReadKnowTypes() .ForEach((v, i) => index = i); } catch (Exception e) { Console.WriteLine(e); throw; } //shapeFile.ReadRawNamedShape() // .ForEach( // v => // { // var dirOutName = Path.Combine(output, realtive); // if (!Directory.Exists(dirOutName)) // { // Directory.CreateDirectory(dirOutName); // } // File.WriteAllBytes(Path.Combine(dirOutName, $"[{v.Id}]_{FileTools.CleanFileName(v.Name)}.bin"), v.RawData); // }); }
/************************************************************************************************************************/ /*****PRIVATE METHODS****************************************************************************************************/ /************************************************************************************************************************/ private void UpdateSpeciesGeographyForTaxonomicClass(String taxonomicClass) { var shapeFileInfo = GetShapeFileInfo(taxonomicClass); using (var shapeFile = new ShapeFile(shapeFileInfo.FullName)) { shapeFile.Open(); const double minLatitude = -3.5; const double maxLatitude = 0.0; const double maxLongitude = 180.0; const double minLongitude = -180.0; const double interval = 0.5; for (var latitude = minLatitude; latitude < maxLatitude; Math.Round(latitude = latitude + interval, 1)) { for (var longitude = minLongitude; longitude < maxLongitude; Math.Round(longitude = longitude + interval, 1)) { var point = GeographyPoint.Create(latitude, longitude); AttemptUpdate: try { UpdateSpeciesGeographyTableIfNeeded(shapeFile, point, taxonomicClass); } catch (Exception e) { Trace.TraceError(e.Message, e); goto AttemptUpdate; } } } } }
internal static Map Default() { string currdir = Directory.GetCurrentDirectory(); Trace.WriteLine(String.Format("Current directory: {0}", currdir)); Map map = new Map(new Size(1, 1)); IDictionary <string, LayerData> dict = Nyc; foreach (string layer in dict.Keys) { string format = String.Format(@"WMS\Server\data\{0}", layer); string path = Path.Combine(currdir, format); if (!File.Exists(path)) { throw new FileNotFoundException("file not found", path); } string name = Path.GetFileNameWithoutExtension(layer); LayerData data = dict[layer]; ShapeFile source = new ShapeFile(path, true); VectorLayer item = new VectorLayer(name, source) { SRID = 4326, Style = (VectorStyle)data.Style, SmoothingMode = SmoothingMode.AntiAlias }; map.Layers.Add(item); } return(map); }
public void TestCachedLineSymbolizerInTheme() { ShapeFile p = new ShapeFile(@"d:\\daten\GeoFabrik\\Aurich\\roads.shp", false); VectorLayer l = new VectorLayer("roads", p); ClsTheme theme = new ClsTheme(l.Style); l.Theme = theme; Map m = new Map(new Size(720, 540)) { BackColor = Color.Cornsilk }; m.Layers.Add(l); m.ZoomToExtents(); Stopwatch sw = new Stopwatch(); sw.Start(); Image bmp = m.GetMap(); sw.Stop(); Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds)); bmp.Save("AurichRoads1Theme.bmp"); }
internal static GeoAPI.Geometries.IGeometry GetGeometryByCode(string file, string shapeColumn, string code) { var features = ShapeFile.ReadShapefile(file + ".shp"); List <string> invalid = new List <string>(); List <string> noParent = new List <string>(); int row = 0; foreach (var feature in features) { row++; string currentCode; if (feature.Attributes[shapeColumn] != null) { currentCode = feature.Attributes[shapeColumn].ToString(); } else { currentCode = null; } if (string.IsNullOrEmpty(currentCode)) { throw new MessageException("El valor para el código no puede se nulo. Fila: " + row.ToString()); } if (currentCode == code) { return(feature.Geometry); } } return(null); }
public static Map OpenLayers() { ICoordinateTransformation transformation = LatLonToGoogle(); HttpContext context = HttpContext.Current; Map map = new Map(new Size(1, 1)); IDictionary <string, LayerData> dict = Nyc; foreach (string layer in dict.Keys) { string format = String.Format("~/App_Data/nyc/{0}.shp", layer); string path = context.Server.MapPath(format); if (!File.Exists(path)) { throw new FileNotFoundException("file not found", path); } LayerData data = dict[layer]; ShapeFile dataSource = new ShapeFile(path, true) { SRID = 900913 }; VectorLayer item = new VectorLayer(layer, dataSource) { Style = (VectorStyle)data.Style, SmoothingMode = SmoothingMode.AntiAlias, CoordinateTransformation = transformation }; map.Layers.Add(item); } return(map); }
public FeatureDataTable GetFeatureTableFromShapefile(string shapeFilePath) { GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices(); int cd; if (!int.TryParse(_enconding.Text, out cd)) { _status.Text = "Bad code page"; } ShapeFile sf = new ShapeFile(shapeFilePath); sf.Encoding = Encoding.GetEncoding(int.Parse(_enconding.Text)); sf.Open(); this.shapeSRID = sf.SRID; this.shapeExtends = sf.GetExtents(); _sRID.Text = this.shapeSRID.ToString(); FeatureDataSet ds = new FeatureDataSet(); sf.ExecuteIntersectionQuery(this.shapeExtends, ds); //ds.Tables[0].Columns.Remove("Oid"); return(ds.Tables[0]); }
internal static Dictionary <string, IGeometry> GetGeometryDictionary(string file, string shapeColumn) { Dictionary <string, IGeometry> ret = new Dictionary <string, IGeometry>(); var features = ShapeFile.ReadShapefile(file + ".shp"); List <string> invalid = new List <string>(); List <string> noParent = new List <string>(); int row = 0; foreach (var feature in features) { row++; string currentCode; if (feature.Attributes[shapeColumn] != null) { currentCode = feature.Attributes[shapeColumn].ToString(); } else { currentCode = null; } if (string.IsNullOrEmpty(currentCode)) { throw new MessageException("El valor para el código no puede se nulo. Fila: " + row.ToString()); } ret.Add(currentCode, feature.Geometry); } return(ret); }
static ShapeFile decodeShapeFile(XmlElement e, Project proj, int pass) { ShapeFile shapeFile = null; if (e != null) { if (pass == 0) { // first pass: create the new source record //source = new Source(); //source.setName(e.GetAttribute("name")); //source.setType(e.GetAttribute("type") == "raster" ? Source.SourceType.TYPE_RASTER : Source.SourceType.TYPE_FEATURE); //source.setURI(e.GetElementsByTagName("uri")[0].InnerText); if (e.GetAttribute("provider") == "ShapeFile") { shapeFile = new ShapeFile(e.GetElementsByTagName("uri")[0].InnerText); } } else { // second pass: reference other sources //source = proj.getSource(e.GetAttribute("name")); //source.setParentSource(proj.getSource(e.GetAttribute("parent"))); } } return shapeFile; }
private void LoadBoundary(String FileName, bool Counties) { CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory(); ICoordinateSystem SourceProj = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(File.ReadAllText(FileName.ToLower().Replace(".shp", ".prj"))) as ICoordinateSystem; ICoordinateSystem DestProj = GeographicCoordinateSystem.WGS84; ICoordinateTransformation XF = ctfac.CreateFromCoordinateSystems(SourceProj, DestProj); using (ShapeFile sF = ShapeFile.Open(FileName)) foreach (Shape shp in sF.GetAllShapes()) { Sim_Boundary NewBoundary = new Sim_Boundary(shp, XF, this); if (Counties) { Boundaries.Add(NewBoundary); } else if (NewBoundary.Contains(Boundaries[0])) { NewBoundary.Name = "STATE"; Boundaries.Add(NewBoundary); } } if (Counties) { Centroid_X /= CoordinateCount; Centroid_Y /= CoordinateCount; } }
public FeatureDataTable GetFeatureTableFromShapefile(string shapeFilePath) { GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices(); int cd; if (!int.TryParse(_enconding.Text, out cd)) { _status.Text = "Bad code page"; } ShapeFile sf = new ShapeFile(shapeFilePath); sf.Encoding = Encoding.GetEncoding(int.Parse(_enconding.Text)); sf.Open(); FeatureDataSet ds = new FeatureDataSet(); importExtent = sf.GetExtents(); Debug.WriteLine("Loading " + sf.GetFeatureCount() + " features from shapefile..."); //sf.ExecuteIntersectionQuery(importExtent, ds); ExecuteRobustIntersectionQuery(sf, importExtent, ds); //ds.Tables[0].Columns.Remove("Oid"); return(ds.Tables[0]); }
public ILayer Create(string layerName, string connectionInfo, VectorLayer.LayerType layertype) { ShapeFile shapeFileData = new ShapeFile(connectionInfo); VectorLayer shapeFileLayer = new VectorLayer(layerName, shapeFileData, layertype); return(shapeFileLayer); }
public IHttpActionResult PostFile() { try { ShapeFile shapeFile = null; DbfReader dbfFile = null; FileMapper fileMapper = null; string[] shpFileStr = Directory.GetFiles(@"C:\testFile", "*.shp"); string[] dbfFilesStr = Directory.GetFiles(@"C:\testFile", "*.dbf"); if (shpFileStr != null && dbfFilesStr != null) { if (shpFileStr.Length == 1 && dbfFilesStr.Length == 1) { shapeFile = new ShapeFile(shpFileStr[0]); dbfFile = new DbfReader(dbfFilesStr[0]); fileMapper = new FileMapper(shapeFile, dbfFile); fileMapper.StartFilter(); } } return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
protected override List <ShapeFile> CreateMapLayers(HttpContext context) { List <ShapeFile> layers = context.Application[MyLayersId] as List <ShapeFile>; if (layers != null) { return(layers); } layers = new List <ShapeFile>(); //load the shapefiles string shapeFilePath = context.Server.MapPath("/demos/new_hampshire_files/new_hampshire_natural.shp"); ShapeFile sf = new ShapeFile(shapeFilePath); layers.Add(sf); shapeFilePath = context.Server.MapPath("/demos/new_hampshire_files/new_hampshire_highway.shp"); sf = new ShapeFile(shapeFilePath); layers.Add(sf); //shapeFilePath = context.Server.MapPath("/demos/demo2_files/j5505_nativevegetationareas.shp"); //sf = new ShapeFile(shapeFilePath); //layers.Add(sf); context.Application[MyLayersId] = layers; return(layers); }
protected override List<ShapeFile> CreateMapLayers(HttpContext context) { List<ShapeFile> layers = new List<ShapeFile>(); //load the shapefiles string shapeFilePath = context.Server.MapPath("/demos/us_demo_files/counties.shp"); ShapeFile sf = new ShapeFile(shapeFilePath); //set the field name used to label the shapes sf.RenderSettings.FieldName = "NAME"; sf.RenderSettings.CustomRenderSettings = CreatePopulationRenderSettings(sf); layers.Add(sf); //set some CustomRenderSettings depending on the render type selected by the user int renderSettingsType = 0; int.TryParse(context.Request["rendertype"], out renderSettingsType); if (renderSettingsType == 0) { layers[0].RenderSettings.CustomRenderSettings = CreatePopulationRenderSettings(layers[0]); } else if (renderSettingsType == 1) { layers[0].RenderSettings.CustomRenderSettings = null; } else { layers[0].RenderSettings.CustomRenderSettings = CustomRenderSettingsUtil.CreateRandomColorCustomRenderSettings(layers[0].RenderSettings, 1); } return layers; }
public bool MoveNext() { if (_shpStream.Position >= _shpHeader.FileLength) { _current = new ShapeFileIndexEntry(); return(false); } // Get the record offset var recordOffset = (int)_shpStream.Position; // Get the oid var oid = ShapeFile.SwapByteOrder(_shpReader.ReadInt32()); Debug.Assert(oid == _lastOid + 1); _lastOid = oid; // Get the record length var recordLength = 2 * ShapeFile.SwapByteOrder(_shpReader.ReadInt32()); // Set the current ShapeFileIndexEntry _current = new ShapeFileIndexEntry(recordOffset, recordLength); // Adjust the streams position _shpStream.Seek(recordLength, SeekOrigin.Current); return(true); }
public static Map InitializeMap() { HttpContext context = HttpContext.Current; Map map = new Map(new Size(1, 1)); foreach (string layer in layers.Keys) { string format = String.Format("~/App_Data/nyc/{0}.shp", layer); string path = context.Server.MapPath(format); if (!File.Exists(path)) { throw new FileNotFoundException("file not found", path); } LayerData data = layers[layer]; ShapeFile dataSource = new ShapeFile(path, true) { SRID = 900913 }; VectorLayer item = new VectorLayer(layer, dataSource) { CoordinateTransformation = data.Transformation, Style = (VectorStyle)data.Style, SmoothingMode = SmoothingMode.AntiAlias }; map.Layers.Add(item); // LabelLayer labels = CreateLabelLayer(item, data.LabelColumn); // map.Layers.Add(labels); } return(map); }
public WindowShapeFileTest(ShapeFileInfo shapeFileInfo) { Areas = new List <string>(); try { _sf = new ShapeFile(shapeFileInfo.Filename); if (_sf.Initialize(shapeFileInfo.TableName, (ShapeFile.CoordType)Enum.Parse(typeof(ShapeFile.CoordType), shapeFileInfo.TCoord), (AreaType)Enum.Parse(typeof(AreaType), shapeFileInfo.TArea), shapeFileInfo.Prefix ?? "", shapeFileInfo.Encoding)) { var ail = _sf.AreaInfos; Areas = (from a in ail orderby a.Name select a.Name).ToList(); } } catch { } InitializeComponent(); _browser = new UIControls.WebBrowserControl(); this.webBrowser.Children.Add(_browser); DataContext = this; this.Closed += WindowShapeFileTest_Closed; }
public void FeatureCount() { string path = TestHelper.GetTestDataPath(TestDataPath.DeltaShell.DeltaShellDeltaShellPluginsSharpMapGisTests, "Europe_Lakes.shp"); IFeatureProvider dataSource = new ShapeFile(path); Assert.AreEqual(37, dataSource.Features.Count); }
public void UseShapefileFeaturesAdFeatureCoverageSource() { string path = Path.Combine(sharpMapGisShapeFilePath, "rivers.shp"); ShapeFile shapeFile = new ShapeFile(path); // select only some features from shapefile Envelope coverageFeatureEnvelope = shapeFile.GetExtents(); coverageFeatureEnvelope.ExpandBy(0.5, 0.5); var coverage = new FeatureCoverage(); coverage.Components.Add(new Variable <double>("value")); coverage.Arguments.Add(new Variable <Feature>("feature")); coverage.Features = new EventedList <IFeature>(shapeFile.Features.Cast <IFeature>()); coverage.FeatureVariable.AddValues(coverage.Features); double[] values = new double[coverage.FeatureVariable.Values.Count]; for (int i = 0; i < values.Length; i++) { values[i] = i; } coverage.SetValues(values); }
/// <summary> /// Creates an instance of this class using the provided <paramref name="headerReader"/>. /// </summary> /// <param name="headerReader">The stream holding the header information</param> public ShapeFileHeader(BinaryReader headerReader) { // Check file header if (headerReader.ReadInt32() != 170328064) { //File Code is actually 9994, but in Little Endian Byte Order this is '170328064' throw (new ApplicationException("Invalid Shapefile (.shp)")); } // Get file length headerReader.BaseStream.Seek(20, SeekOrigin.Current); FileLength = 2 * ShapeFile.SwapByteOrder(headerReader.ReadInt32()); // Check file Version if (headerReader.ReadInt32() != ShapeFileVersion) { throw (new ApplicationException("Invalid Shapefile version")); } // Get the shape type ShapeType = (ShapeType)headerReader.ReadInt32(); // Get the bounding box _envelope = new Envelope(new Coordinate(headerReader.ReadDouble(), headerReader.ReadDouble()), new Coordinate(headerReader.ReadDouble(), headerReader.ReadDouble())); // Get the Z-range ZRange = Interval.Create(headerReader.ReadDouble(), headerReader.ReadDouble()); // Get the Z-range MRange = Interval.Create(ParseNoDataValue(headerReader.ReadDouble()), ParseNoDataValue(headerReader.ReadDouble())); }
protected override List <ShapeFile> CreateMapLayers(HttpContext context) { List <ShapeFile> layers = new List <ShapeFile>(); //load the shapefiles string shapeFilePath = context.Server.MapPath("/demos/us_demo_files/counties.shp"); ShapeFile sf = new ShapeFile(shapeFilePath); //set the field name used to label the shapes sf.RenderSettings.FieldName = "NAME"; sf.RenderSettings.CustomRenderSettings = CreatePopulationRenderSettings(sf); layers.Add(sf); //set some CustomRenderSettings depending on the render type selected by the user int renderSettingsType = 0; int.TryParse(context.Request["rendertype"], out renderSettingsType); if (renderSettingsType == 0) { layers[0].RenderSettings.CustomRenderSettings = CreatePopulationRenderSettings(layers[0]); } else if (renderSettingsType == 1) { layers[0].RenderSettings.CustomRenderSettings = null; } else { layers[0].RenderSettings.CustomRenderSettings = CustomRenderSettingsUtil.CreateRandomColorCustomRenderSettings(layers[0].RenderSettings, 1); } return(layers); }
public static Map Default() { HttpContext context = HttpContext.Current; Map map = new Map(new Size(1, 1)); IDictionary <string, LayerData> dict = Nyc; foreach (string layer in dict.Keys) { string format = String.Format("~/App_Data/{0}", layer); string path = context.Server.MapPath(format); if (!File.Exists(path)) { throw new FileNotFoundException("file not found", path); } string name = Path.GetFileNameWithoutExtension(layer); LayerData data = dict[layer]; ShapeFile source = new ShapeFile(path, true); VectorLayer item = new VectorLayer(name, source) { SRID = 4326, Style = (VectorStyle)data.Style, SmoothingMode = SmoothingMode.AntiAlias }; map.Layers.Add(item); } return(map); }
public void GetFeatureShouldWorkForShapeFileWithoutObjectID() { string path = @"..\..\..\..\data\gemeenten.shp"; var s = new ShapeFile(path); var feature = s.Features[0]; Assert.LessOrEqual(0, s.IndexOf((IFeature)feature)); }
public void ContainsShouldWorkForShapeFile() { string path = TestHelper.GetTestDataPath(@"DeltaShell\DeltaShell.Plugins.SharpMapGis.Tests\", "Europe_Lakes.shp"); var s = new ShapeFile(path); var feature = s.Features[0]; s.Contains((IFeature)feature); // -> should not throw an exception }
public void GetFeatureShouldWorkForShapeFile() { string path = @"..\..\..\..\data\Europe_Lakes.shp"; var s = new ShapeFile(path); var feature = s.Features[1]; Assert.LessOrEqual(0, s.IndexOf((IFeature)feature)); }
/// <summary> /// Constructs a ShapeFile using a path to a .shp shape file /// </summary> /// <param name="shapeFilePath">The path to the ".shp" shape file</param> private Shape(string shapeFilePath) { using (var file = new ShapeFile(shapeFilePath)) { RecordCount = file.RecordCount; ShapeData = new IEnumerable<PointXYZ[]>[RecordCount]; for (int i = 0; i < RecordCount; ++i) { var shapeData = file.GetShapeDataD(i); ShapeData[i] = shapeData.Select(x => x.Select(p => new PointXYZ() { X = p.X, Y = p.Y, Z = 0 }).ToArray()); } } string dbfFilePath = Path.ChangeExtension(shapeFilePath, "dbf"); Database = new DbfReader(dbfFilePath); }
private static ICustomRenderSettings CreatePopulationRenderSettings(ShapeFile sf) { Color[] populationColors = new Color[]{Color.FromArgb(255,255,128), Color.FromArgb(220,225,65), Color.FromArgb(255,245,0), Color.FromArgb(255,128,0), Color.FromArgb(255,64,0), Color.FromArgb(255,0,0)}; //synchronize the creation. Another thread may be attempting to render //the map or create a custom render settings and reading from the //internal DBFReader is not thread safe lock (EGIS.ShapeFileLib.ShapeFile.Sync) { return CustomRenderSettingsUtil.CreateQuantileCustomRenderSettings( sf.RenderSettings, populationColors, "POP90_SQMI"); } }
protected override void GetCustomTooltipText(HttpContext context, ShapeFile layer, int recordIndex, ref string tooltipText) { //override the default ToolTip text - we will just return all attributes for the record if (recordIndex >= 0) { string[] fieldNames = layer.RenderSettings.DbfReader.GetFieldNames(); string[] values = layer.RenderSettings.DbfReader.GetFields(recordIndex); System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<table>"); for (int n = 0; n < fieldNames.Length; ++n) { sb.Append("<tr>"); sb.Append("<td>").Append(fieldNames[n]).Append("</td>"); sb.Append("<td>").Append(values[n]).Append("</td>"); sb.Append("</tr>"); } sb.Append("</table>"); tooltipText = sb.ToString(); } }
public static Map PolyMaps() { HttpContext context = HttpContext.Current; Map map = new Map(new Size(1, 1)); foreach (string layer in layers.Keys) { string format = String.Format("~/App_Data/nyc/{0}.shp", layer); string path = context.Server.MapPath(format); if (!File.Exists(path)) throw new FileNotFoundException("file not found", path); LayerData data = layers[layer]; ShapeFile dataSource = new ShapeFile(path, true) { SRID = 4326 }; VectorLayer item = new VectorLayer(layer, dataSource) { Style = (VectorStyle)data.Style, SmoothingMode = SmoothingMode.AntiAlias }; map.Layers.Add(item); } return map; }
public bool Initialize() { Clear(); var items = Settings.Settings.Default.GetShapeFileItems(); foreach (var item in items) { try { if (item.Enabled != 0) { if (System.IO.File.Exists(item.FileName)) { ShapeFile sf = new ShapeFile(item.FileName); if (sf.Initialize(item.TableName, (ShapeFile.CoordType)Enum.Parse(typeof(ShapeFile.CoordType), item.CoordType), (AreaType)Enum.Parse(typeof(AreaType), item.AreaType), item.NamePrefix??"", item.Encoding)) { _shapeFiles.Add(sf); } } } } catch { } } if (PropertyChanged!=null) { PropertyChanged(this, new PropertyChangedEventArgs("")); } return true; }
protected virtual void GetCustomTooltipText(HttpContext context, ShapeFile layer, int recordIndex, ref string tooltipText) { }