本文整理汇总了C#中SharpMap.Layers.VectorLayer类的典型用法代码示例。如果您正苦于以下问题:C# VectorLayer类的具体用法?C# VectorLayer怎么用?C# VectorLayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VectorLayer类属于SharpMap.Layers命名空间,在下文中一共展示了VectorLayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupMap
/// <summary>
/// little util wich just adds one vector layer to the map and assigns it a random theme.
/// </summary>
/// <param name="context"></param>
/// <param name="m"></param>
public static void SetupMap(HttpContext context, Map m)
{
var l = new VectorLayer(
"Countries",
new ShapeFile(context.Server.MapPath(ConfigurationManager.AppSettings["shpfilePath"])));
l.Style = RandomStyle.RandomVectorStyleNoSymbols();
l.Theme = new CustomTheme<IVectorStyle>(
delegate { return RandomStyle.RandomVectorStyleNoSymbols(); });
m.Layers.Add(l);
FeatureDataTable labelData = new FeatureDataTable();
labelData.Columns.Add("Name", typeof (string));
FeatureDataRow r = labelData.NewRow();
r["Name"] = "My Lair";
r.Geometry = new Point(5, 5);
labelData.AddRow(r);
LabelLayer labelLayer = new LabelLayer("labelLayer")
{
DataSource = new GeometryFeatureProvider(labelData),
Enabled = true,
LabelColumn = "Name",
Style = new LabelStyle
{
BackColor = new SolidBrush(Color.Black),
ForeColor = Color.White,
Halo = new Pen(Color.Yellow, 0.1F),
CollisionDetection = false,
Font = new Font("Arial", 10, GraphicsUnit.Point)
}
};
m.Layers.Add(labelLayer);
}
示例2: GridProfileTool
public GridProfileTool(MapControl mapControl)
: base(mapControl)
{
GridProfiles = new List<IFeature>();
VectorLayer profileLayer = new VectorLayer("Profile Layer")
{
DataSource = new FeatureCollection(GridProfiles, typeof(GridProfile)),
Enabled = true,
Style = new VectorStyle
{
Fill = new SolidBrush (Color.Tomato),
Symbol = null,
Line = new Pen(Color.SteelBlue, 1),
Outline = new Pen(Color.FromArgb(50, Color.LightGray), 3)
},
Map = mapControl.Map,
ShowInTreeView = true
};
Layer = profileLayer;
newLineTool = new NewLineTool(profileLayer)
{
MapControl = mapControl,
Name = "ProfileLine",
AutoCurve = false,
MinDistance = 0,
IsActive = false
};
}
示例3: MutatingAGroupLayerWithHasReadonlyLayerCollectionThrows
public void MutatingAGroupLayerWithHasReadonlyLayerCollectionThrows()
{
var layerGroup = new GroupLayer {HasReadOnlyLayersCollection = true};
var childLayer = new VectorLayer();
layerGroup.Layers.Add(childLayer);
}
示例4: Form2_Load
private void Form2_Load(object sender, EventArgs e)
{
//TileAsyncLayer osmLayer= new TileAsyncLayer(new OsmTileSource(), "TileLayer - OSM");
TileAsyncLayer bingLayer = new TileAsyncLayer(new BingTileSource(BingRequest.UrlBing, "",BingMapType.Roads), "TileLayer - Bing" );
this.mapBox1.Map.BackgroundLayer.Add(bingLayer);
#if DotSpatialProjections
var mathTransform = LayerTools.Wgs84toGoogleMercator;
SharpMap.Geometries.BoundingBox geom = GeometryTransform.TransformBox(
new SharpMap.Geometries.BoundingBox(-9.205626, 38.690993, -9.123736, 38.740837),
mathTransform.Source, mathTransform.Target);
#else
var mathTransform = LayerTools.Wgs84toGoogleMercator.MathTransform;
SharpMap.Geometries.BoundingBox geom = GeometryTransform.TransformBox(
new SharpMap.Geometries.BoundingBox(-9.205626, 38.690993, -9.123736, 38.740837),
mathTransform);
#endif
//Adds a pushpin layer
VectorLayer pushPinLayer = new VectorLayer("PushPins");
List<SharpMap.Geometries.Geometry> geos = new List<SharpMap.Geometries.Geometry>();
geos.Add(geom.GetCentroid());
SharpMap.Data.Providers.GeometryProvider geoProvider = new SharpMap.Data.Providers.GeometryProvider(geos);
pushPinLayer.DataSource = geoProvider;
//this.mapBox1.Map.Layers.Add(pushPinLayer);
this.mapBox1.Map.ZoomToBox(geom);
this.mapBox1.Map.Zoom = 8500;
this.mapBox1.Refresh();
}
示例5: SetAttributes
public void SetAttributes()
{
Collection<IGeometry> geometries = new Collection<IGeometry>();
geometries.Add(GeometryFromWKT.Parse("LINESTRING (20 20, 20 30, 30 30, 30 20, 40 20)"));
geometries.Add(GeometryFromWKT.Parse("LINESTRING (21 21, 21 31, 31 31, 31 21, 41 21)"));
geometries.Add(GeometryFromWKT.Parse("LINESTRING (22 22, 22 32, 32 32, 32 22, 42 22)"));
DataTableFeatureProvider dataTableFeatureFeatureProvider = new DataTableFeatureProvider(geometries);
VectorLayer vectorLayer = new VectorLayer();
vectorLayer.DataSource = dataTableFeatureFeatureProvider;
// add column
FeatureDataRow r = (FeatureDataRow)vectorLayer.DataSource.GetFeature(0);
r.Table.Columns.Add("Value", typeof(float));
// set value attribute
for (int i = 0; i < dataTableFeatureFeatureProvider.GetFeatureCount(); i++)
{
r = (FeatureDataRow)dataTableFeatureFeatureProvider.GetFeature(i);
r[0] = i;
}
FeatureDataRow row = (FeatureDataRow)dataTableFeatureFeatureProvider.GetFeature(2);
Assert.AreEqual(2, row[0], "Attribute 0 in the second feature must be set to 2");
}
示例6: ShowMapWithPointLayerBasedOnFeatureDataTable
public void ShowMapWithPointLayerBasedOnFeatureDataTable()
{
var table = new FeatureDataTable();
table.Columns.Add("X", typeof(double));
table.Columns.Add("Y", typeof(double));
table.Columns.Add("Category", typeof(string));
DataRow row = table.NewRow();
table.Rows.Add(row);
row.ItemArray = new object[] { 100000, 400000, "testCategory" };
row = table.NewRow();
table.Rows.Add(row);
row.ItemArray = new object[] { 200000, 400000, "TestCategory" };
var dataTablePoint = new DataTablePoint(table, "Category", "X", "Y");
var vectorLayer = new VectorLayer("test", dataTablePoint);
vectorLayer.Theme =ThemeFactory.CreateSingleFeatureTheme(vectorLayer.Style.GeometryType, Color.Blue, 10);
var map = new Map { Name = "testmap" };
map.Layers.Add(vectorLayer);
map.Center = new Coordinate(150000, 400000);
map.Zoom = 200000;
//map.ZoomToExtents();
//map.ZoomToBox(map.Envelope);
MapTestHelper.Show(map);
}
示例7: FindGeoNearPoint
public static FeatureDataRow FindGeoNearPoint(GeoAPI.Geometries.IPoint point, VectorLayer layer, double amountGrow)
{
var box = new Envelope(point.Coordinate);
box.ExpandBy(amountGrow);
var fds = new FeatureDataSet();
layer.DataSource.ExecuteIntersectionQuery(box, fds);
FeatureDataRow result = null;
var minDistance = double.MaxValue;
foreach (FeatureDataTable fdt in fds.Tables)
{
foreach (FeatureDataRow fdr in fdt.Rows)
{
if (fdr.Geometry != null)
{
var distance = point.Distance(fdr.Geometry);
if (distance < minDistance)
{
result = fdr;
minDistance = distance;
}
}
}
}
return result;
}
示例8: InitializeDXF
private static Map InitializeDXF(float angle)
{
Map map = new Map();
//Set the datasource to a shapefile in the App_data folder
Ogr provider;
try
{
provider = new Ogr("GeoData/SampleDXF.dxf",0);
}
catch (TypeInitializationException ex)
{
if (ex.Message == "The type initializer for 'OSGeo.OGR.Ogr' threw an exception.")
{
throw new Exception(
String.Format(
"The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. They are a part of fwtools {0}. You can download it from: http://home.gdal.org/fwtools/",
GdalRasterLayer.FWToolsVersion));
}
throw;
}
VectorLayer lay = new VectorLayer("SampleDXF", provider);
map.Layers.Add(lay);
map.ZoomToExtents();
Matrix mat = new Matrix();
mat.RotateAt(angle, map.WorldToImage(map.Center));
map.MapTransform = mat;
_ogrSampleDataset = "SampleDXF";
return map;
}
示例9: CoverageProfileTool
public CoverageProfileTool()
{
GridProfiles = new List<IFeature>();
profileLayer = new VectorLayer("Profile Layer")
{
DataSource = new FeatureCollection(GridProfiles, typeof(CoverageProfile)),
Visible = true,
Style = new VectorStyle
{
Fill = new SolidBrush (Color.Tomato),
Symbol = null,
Line = new Pen(Color.Tomato, 2),
Outline = new Pen(Color.FromArgb(50, Color.Tomato), 2)
},
ShowInTreeView = true,
FeatureEditor = new CoverageProfileEditor()
};
LayerFilter = l => l.Equals(profileLayer);
newLineTool = new NewLineTool(l => l.Equals(profileLayer), "new coverage profile")
{
AutoCurve = false,
MinDistance = 0,
IsActive = false
};
}
示例10: CreateFromCollection
public void CreateFromCollection()
{
EventedList<SampleFeature> features = new EventedList<SampleFeature>();
features.Add(new SampleFeature());
features.Add(new SampleFeature());
features.Add(new SampleFeature());
features[0].Geometry = GeometryFromWKT.Parse("LINESTRING (20 20, 20 30, 30 30, 30 20, 40 20)");
features[1].Geometry = GeometryFromWKT.Parse("LINESTRING (30 30, 30 40, 40 40, 40 30, 50 30)");
features[2].Geometry = GeometryFromWKT.Parse("LINESTRING (40 40, 40 50, 50 50, 50 40, 60 40)");
FeatureCollection featureCollection = new FeatureCollection {Features = features};
Map map = new Map();
VectorLayer vectorLayer = new VectorLayer();
vectorLayer.DataSource = featureCollection;
map.Layers.Add(vectorLayer);
Assert.AreEqual(3, vectorLayer.DataSource.GetFeatureCount());
Assert.AreEqual("LineString", vectorLayer.DataSource.GetGeometryByID(0).GeometryType);
// ShowMap(map);
}
示例11: ClearSelectionOnParentGroupLayerRemove
public void ClearSelectionOnParentGroupLayerRemove()
{
var featureProvider = new DataTableFeatureProvider();
featureProvider.Add(new WKTReader().Read("POINT(0 0)"));
var layer = new VectorLayer { DataSource = featureProvider };
var groupLayer = new GroupLayer { Layers = { layer } };
using (var mapControl = new MapControl { Map = { Layers = { groupLayer } }, AllowDrop = false })
{
var selectTool = mapControl.SelectTool;
selectTool.Select(featureProvider.Features.Cast<IFeature>());
WindowsFormsTestHelper.Show(mapControl);
mapControl.Map.Layers.Remove(groupLayer);
mapControl.WaitUntilAllEventsAreProcessed();
selectTool.Selection
.Should("selection is cleared on layer remove").Be.Empty();
}
WindowsFormsTestHelper.CloseAll();
}
示例12: Spherical
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);
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;
}
示例13: NewNodeToolShouldWorkWithoutSnapRules
public void NewNodeToolShouldWorkWithoutSnapRules()
{
// Create map and map control
Map map = new Map();
var nodeList = new List<Node>();
var nodeLayer = new VectorLayer
{
DataSource = new FeatureCollection(nodeList, typeof (Node)),
Visible = true,
Style = new VectorStyle
{
Fill = new SolidBrush(Color.Tomato),
Symbol = null,
Line = new Pen(Color.Turquoise, 3)
}
};
map.Layers.Add(nodeLayer);
var mapControl = new MapControl {Map = map};
mapControl.Resize += delegate { mapControl.Refresh(); };
mapControl.Dock = DockStyle.Fill;
var newNodeTool = new NewNetworkFeatureTool(l => true, "new node");
mapControl.Tools.Add(newNodeTool);
var args = new MouseEventArgs(MouseButtons.Left, 1, -1, -1, -1);
newNodeTool.OnMouseDown(new Coordinate(0, 20), args);
newNodeTool.OnMouseMove(new Coordinate(0, 20), args);
newNodeTool.OnMouseUp(new Coordinate(0, 20), args);
Assert.IsFalse(newNodeTool.IsBusy);
Assert.AreEqual(1, nodeList.Count);
}
示例14: CanRemovePointFromLine
[Test] //not working in UI?
public void CanRemovePointFromLine()
{
var mapControl = new MapControl();
var vectorLayer = new VectorLayer();
var layerData = new FeatureCollection();
vectorLayer.DataSource = layerData;
layerData.FeatureType = typeof(CloneableFeature);
layerData.Add(new LineString(new[] { new Coordinate(0, 0), new Coordinate(50, 0), new Coordinate(100, 0) }));
mapControl.Map.Layers.Add(vectorLayer);
var firstFeature = (IFeature)layerData.Features[0];
mapControl.SelectTool.Select(firstFeature);
var curveTool = mapControl.GetToolByType<CurvePointTool>();
curveTool.IsActive = true;
curveTool.Mode = CurvePointTool.EditMode.Remove;
var args = new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0);
curveTool.OnMouseMove(new Coordinate(50, 0), new MouseEventArgs(MouseButtons.None, 1, 0, 0, 0));
curveTool.OnMouseDown(new Coordinate(50, 0), args); // delete tracker
Assert.AreEqual(2, firstFeature.Geometry.Coordinates.Length);
Assert.AreEqual(100.0, firstFeature.Geometry.Coordinates[1].X);
}
示例15: FormAnimation_Load
private void FormAnimation_Load(object sender, EventArgs e)
{
//Set up the countries layer
VectorLayer layCountries = new VectorLayer("Countries");
//Set the datasource to a shapefile in the App_data folder
layCountries.DataSource = new ShapeFile("GeoData/World/countries.shp", true);
//Set fill-style to green
layCountries.Style.Fill = new SolidBrush(Color.Green);
//Set the polygons to have a black outline
layCountries.Style.Outline = Pens.Black;
layCountries.Style.EnableOutline = true;
layCountries.SRID = 4326;
this.mapBox1.Map.Layers.Add(layCountries);
this.mapBox1.Map.ZoomToExtents();
this.mapBox1.Refresh();
}