免責事項: 私は GIS の専門家ではありません。
DotSpatial ライブラリを使用してライン ポリゴンの交点を計算し、その交点を WPF Bing Maps コントロールに表示しようとしています。何らかの理由で、東西方向に完全にまっすぐでない交点は、Bing の元の線から下にずれて表示されます。WGS1984 に投影された DotSpatial コントロールですべてを表示すると、シフトが発生しないため、これは投影の問題であると想定しています。
再作成するには、マップ ウィンドウの xaml コード ビハインドに次のコードを追加します。
using Microsoft.Maps.MapControl.WPF;
using System.Windows;
using System.Windows.Media;
using DotSpatial.Data;
using DotSpatial.Topology;
public partial class MainWindow : Window
{
private LocationCollection _polygonLocs = new LocationCollection();
public MainWindow ()
{
InitializeComponent();
AddSquarePolygon();
// angled line 1
LocationCollection slantedLocs = new LocationCollection();
slantedLocs.Add(new Microsoft.Maps.MapControl.WPF.Location(40, -97));
slantedLocs.Add(new Microsoft.Maps.MapControl.WPF.Location(35, -86));
AddAndIntersectLine( slantedLocs );
// straight EW line
LocationCollection ewLocs = new LocationCollection();
ewLocs.Add(new Microsoft.Maps.MapControl.WPF.Location(37, -97));
ewLocs.Add(new Microsoft.Maps.MapControl.WPF.Location(37, -86));
AddAndIntersectLine(ewLocs);
}
private void AddAndIntersectLine(LocationCollection lineLocs)
{
MapPolyline line = new MapPolyline() { Locations = lineLocs, Stroke = new SolidColorBrush(Colors.Black) };
this._bingMap.Children.Add(line);
LocationCollection inters = Intersect(lineLocs, _polygonLocs);
MapPolyline interLine = new MapPolyline() { Locations = inters, Stroke = new SolidColorBrush(Colors.Red) };
this._bingMap.Children.Add(interLine);
}
private void AddSquarePolygon()
{
_polygonLocs.Add(new Microsoft.Maps.MapControl.WPF.Location(39.0, -92));
_polygonLocs.Add(new Microsoft.Maps.MapControl.WPF.Location(36.0, -92));
_polygonLocs.Add(new Microsoft.Maps.MapControl.WPF.Location(36.0, -93));
_polygonLocs.Add(new Microsoft.Maps.MapControl.WPF.Location(39.0, -93));
MapPolygon square = new MapPolygon()
{
Locations = _polygonLocs,
Stroke = new SolidColorBrush(Colors.Black)
};
this._bingMap.Children.Add(square);
}
public static LocationCollection Intersect(LocationCollection line, LocationCollection bounds)
{
Feature lineFeature = CreateFeatureFromLocations(line);
Feature boundsFeature = CreateFeatureFromLocations(bounds);
IFeature featureIntersection = boundsFeature.Intersection(lineFeature);
if (featureIntersection != null)
{
return (CreateLocationsFromFeature(featureIntersection));
}
return new LocationCollection();
}
private static LocationCollection CreateLocationsFromFeature(IFeature feature)
{
LocationCollection lc = new LocationCollection();
foreach (var coords in feature.Coordinates)
{
lc.Add(new Microsoft.Maps.MapControl.WPF.Location(coords.Y, coords.X));
}
return lc;
}
private static Feature CreateFeatureFromLocations(LocationCollection locs)
{
Coordinate[] coords = new Coordinate[locs.Count];
long inx = 0;
foreach (var l in locs)
{
Coordinate coord = new Coordinate();
coord.X = l.Longitude;
coord.Y = l.Latitude;
coords[inx] = coord;
inx++;
}
LineString ls = new LineString(coords);
MultiLineString mls = new MultiLineString(ls);
return new Feature(mls);
}
}