public void Read() { Collection.Clear(); System.IO.StringReader stream = new System.IO.StringReader(Properties.Resources.countryBoundaries); using (TextFieldParser parser = new TextFieldParser(stream)) { parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(","); while (!parser.EndOfData) { // Processing row string[] fields = parser.ReadFields(); if (fields != null) { string country = fields[6]; WSMCountry cDef = new WSMCountry(country) { Brush = null }; _initPolyInfo(fields[0]); while (true) { WSMPolygon poly = _getNextPoly(); if (poly == null) { break; } cDef.AddPolygon(poly); if (poly.Polytype == 1) { cDef.HasInternalBorders = true; } } if (cDef.Collection.Count > 0) { if (cDef.Collection.Count > 1) { cDef.Collection.Sort((p1, p2) => (p1.Polytype - p2.Polytype)); } cDef.Finish(); Collection.Add(cDef); } } } } }
PointF[] _getPoly(WSMPolygon poly) { var _poly = new List <PointF>(); foreach (BaseCoordinate item in poly.Collection) { if (!double.IsNaN(item.ProjectedX)) { _poly.Add(_convertF(item)); } } if (_poly.Count <= 2) { return(null); } return(_poly.ToArray()); }
private WSMPolygon _getNextPoly() { WSMPolygon poly = new WSMPolygon(); int idx0 = _polyInfo.IndexOf(_head, _polyPos, StringComparison.Ordinal); if (idx0 == -1) { return(null); } // which head? string tail; if (_polyInfo.Substring(idx0 - _outer.Length, _outer.Length) == _outer) { tail = _tailO; poly.Polytype = 0; } else if (_polyInfo.Substring(idx0 - _inner.Length, _inner.Length) == _inner) { tail = _tailI; poly.Polytype = 1; } else { return(null); } int idx1 = _polyInfo.IndexOf(tail, _polyPos + _head.Length, StringComparison.Ordinal); if (idx1 == -1) { return(null); } idx0 = idx0 + _head.Length; _polyPos = idx1 + tail.Length; string coords = _polyInfo.Substring(idx0, idx1 - idx0); string[] part = coords.Split(", ".ToArray()); for (int i = 0; i < part.Length; i += 3) { try { poly.AddCoordinate(double.Parse(part[i + 1]), double.Parse(part[i])); } catch { // ignored } } if (poly.Collection.Count > 2) { return(poly); } else { return(null); } }
internal void AddPolygon(WSMPolygon poly) { Collection.Add(poly); }