我必须制作一个国家的2D地图。 我读出了一个GEOJson文件,在该文件中,我分配了转换为点的坐标,并用这些点创建了多边形。当我将普罗旺斯分开显示时没有问题。当我尝试连接每个多边形(出处)时,会得到线的分配。drawing in xaml。
我必须得到没有线条的相同图纸。
使用的代码是这样的:
public void makePolygon()
{
double x = 0;
double y = 0;
PointReduction pr = new PointReduction();
string filepath = "C:/Users/tomcr/Onedrive/Bureaublad/AppliedProgram/Belgie.GEOJSON";
using (StreamReader streamReader = new StreamReader(filepath))
using (JsonTextReader reader = new JsonTextReader(streamReader))
{
reader.SupportMultipleContent = true;
var serializer = new JsonSerializer();
while (reader.Read())
{
if (reader.TokenType == JsonToken.StartObject)
{
string jsonString = JObject.Load(reader).ToString();
JsonModel.Rootobject rootobject = JsonConvert.DeserializeObject<JsonModel.Rootobject>(jsonString);
PointCollection myPointCollection = new PointCollection();
List<Point> pointListOut = new List<Point>();
PointCollection PLO = new PointCollection();
Polygon myPolygon = new Polygon();
for (int i = 0; i < rootobject.features.Length; i++)
{
myPolygon = new Polygon();
string naam = rootobject.features[i].properties.localname;
JsonModel.Geometry geometrie = rootobject.features[i].geometry;
for (int p = 0; p < geometrie.coordinates.Length; p++)
{
for (int j = 0; j < geometrie.coordinates[p].Length; j++)
{
for (int z = 0; z < geometrie.coordinates[p][j].Length; z++)
{
double lon = DegreeToRadian((geometrie.coordinates[p][j][z][0]));
double lat = DegreeToRadian((geometrie.coordinates[p][j][z][1]));
x = (1000 / (2 * Math.PI) * Math.Pow(2, 6) * (lon + Math.PI));
y = (1000 / (2 * Math.PI) * Math.Pow(2, 6) * (Math.PI - Math.Log(Math.Tan(Math.PI / 4 + lat / 2))));
myPointCollection.Add(new System.Windows.Point(x, y));
}
}
}
pr.RamerDouglasPeucker(myPointCollection, 1.0, pointListOut);
PLO = pr.Omvorm(pointListOut);
myPolygon.Points = PLO;
myPolygon.Stroke = Brushes.Black;
myPolygon.Stretch = Stretch.Fill;
myPolygon.StrokeThickness = 2;
}
myCanvas.Children.Add(myPolygon);
}
}
}
}
数据被使用是这样的: { “ type”:“ FeatureCollection”, “特征” : [{ “ type”:“功能”, “属性”:{ “ srid”:“ 4326”, “ id”:“ 54094”, “名称”:“布鲁塞尔首都”, “ localname”:“布鲁塞尔大都会-布鲁塞尔Hoofdstedelijk Gewest”, “官方名字” : ””, “ boundary”:“行政”, “ admin_level”:“ 4”, “注意” : ””, “ wikidata”:“ Q240”, “ wikipedia”:“ fr:Régionde Bruxelles-Capitale”, “ timestamp”:“ 2019-12-11 22:37:02”, “ rpath”:“ 54094,52411,0”, “ alltags”:{ “ name:ar”:“بروكسلالعاصمة”, “ name:ca”:“布鲁塞尔·首都”, “ name:en”:“布鲁塞尔首都”, “ name:fr”:“ Bruxelles-Capitale”, “ name:nl”:“布鲁塞尔Hoofdstedelijk Gewest”, “ name:ru”:“Брюссельскийстоличныйрегион”, “ name:sk”:“Bruselskýregión”, “ name:wa”:“Brussele-Capitåle”, “ ref:INS”:“ 04000”, “ website”:“ http://www.bruxelles.irisnet.be/”, “名称:vls”:“ HaaptstadBréissel”, “ nat_name”:“Régionde Bruxelles-Capitale-布鲁塞尔Hoofdstedelijk Gewest”, “ wikidata”:“ Q240”, “ ISO3166-2”:“ BE-BRU”, “ wikipedia”:“ fr:Régionde Bruxelles-Capitale”, “ nat_name:ar”:“إقليمبروكسلالعاصمة”, “ nat_name:ca”:“布鲁塞尔-首都大区”, “ nat_name:de”:“地区布鲁塞尔-乌普施塔特” “ nat_name:en”:“布鲁塞尔首都大区”, “ nat_name:fr”:“布鲁塞尔大区首都” “ nat_name:lb”:“ HaaptstadregiounBréissel”, “ nat_name:li”:“布鲁塞尔胡佛斯大学”, “ nat_name:nl”:“布鲁塞尔Hoofdstedelijk Gewest”, “ nat_name:wa”:“布鲁塞尔-Capitåle的Redjon”, “ nat_name:vls”:“布鲁塞尔Oofdstedelik Gewest”, “ default_language”:“ fr-nl”} }, “ bbox”:[4.2437658、50.763683、4.4822712、50.913906], “ geometry”:{“ type”:“ MultiPolygon”,“ coordinates”:[[[[[4.2437658,50.8195819],[4.2443812,50.8195414],[4.2444378,50.8193993],[4.2446464,50.8188349],[4.25431,50.8262863], [4.2539027,50.8258845],[4.2531563,50.8251469],[4.2511811,50.8242196],[4.2508417,50.8243805],[4.2497516,50.8235688],[4.2479386,50.8221951],[4.2476042,50.8219406],[4.2470097,50.8215331],[4.2453656 ,50.8205113],[4.244301,50.8198943],[4.2437658,50.8195819]]]]} },{ “ type”:“功能”, “属性”:{ “ srid”:“ 4326”, “ id”:“ 53114”, “名称”:“安特卫普”, “ localname”:“ Antwerpen”, “ official_name”:“安特卫普省”, “ boundary”:“行政”, “ admin_level”:“ 6”, “注意” : ””, “ wikidata”:“ Q1116”, “ wikipedia”:“ nl:安特卫普(省)”, “ timestamp”:“ 2019-12-20 22:59:01”, “ rpath”:“ 53114,53134,52411,0”, “ alltags”:{ “ name:ca”:“Provínciad'Anvers”, “ name:en”:“安特卫普”, “ name:es”:“ Amberes”, “ name:fr”:“ Anvers”, “ name:lt”:“ Antverpenas”, “ name:mk”:“Антверпен”, “ name:nl”:“ Antwerpen”, “ name:pl”:“安特卫普”, “ name:ru”:“Антверпен”, “ name:sk”:“ Antverpy”, “ ref:INS”:“ 10000”, “ website”:“ http://www.provant.be/”, “ name:tzl”:“Anviarça”, “ wikidata”:“ Q1116”, “ ISO3166-2”:“ BE-VAN”, “ wikipedia”:“ nl:安特卫普(省)”, “人口”:“ 1802719”, “ alt_name:mk”:“Антверп”, “ border_type”:“省”, “ wikipedia:fr”:“安沃省”, “ official_name”:“安特卫普省”, “ population:date”:“ 2014-01-01”, “ official_name:nl”:“安特卫普省”} }, “ bbox”:[4.1719656、50.990143、5.2622542、51.505116], “ geometry”:{“ type”:“ MultiPolygon”,“ coordinates”:[[[[[4.9399714,51.4361185],[4.9394687,51.4371095],[4.9457065,51.4447059],[4.9458012,51.4439747],[4.9439971,51.443798], [4.9439697,51.4437954],[4.9439041,51.4437889]]],[[[4.948755,51.4549908],[4.9490227,51.4537654],[4.949351,51.4537897],[4.9492362,51.4542513],[4.9497913,51.4543045],[4.9495907,51.4551116 ],[4.9490426,51.4550324],[4.948755,51.4549908]]]]} } (我删除了坐标分配)
答案 0 :(得分:0)
不可能在没有看到数据本身的情况下肯定地回答此问题,但是乍一看,我看到您没有为创建的每个PointCollection
对象创建新的PLO Polygon
。
我怀疑您可能还需要从Polygon
切换到Polyline
,但这又取决于您数据的性质。
答案 1 :(得分:0)
问题解决了,我为每个普罗旺斯制作了一个多边形,我不得不将其删除 “ myPolygon.Stretch = Stretch.Fill;”