本文整理汇总了C#中OsmSharp类的典型用法代码示例。如果您正苦于以下问题:C# OsmSharp类的具体用法?C# OsmSharp怎么用?C# OsmSharp使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OsmSharp类属于命名空间,在下文中一共展示了OsmSharp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Convert
/// <summary>
/// Converts the given OsmSharp feature collection into a list of NTS feature collection.
/// </summary>
/// <param name="featureCollection"></param>
/// <returns></returns>
public static List<Feature> Convert(OsmSharp.Geo.Features.FeatureCollection featureCollection)
{
var features = new List<Feature>(featureCollection.Count);
foreach (var feature in featureCollection)
{
features.Add(OsmSharpToNTSFeatureConvertor.Convert(feature));
}
return features;
}
开发者ID:APLANA-Alexey-Stolyarov,项目名称:OsmSharpDataProcessor,代码行数:14,代码来源:OsmSharpToNTSFeatureConvertor.cs
示例2: ConvertBoundary
/// <summary>
/// Converts boundary type into an osm object.
/// </summary>
/// <param name="boundary"></param>
/// <returns></returns>
private static IEnumerable<LineairRing> ConvertBoundary(OsmSharp.IO.Xml.Kml.v2_1.boundaryType[] boundary)
{
List<LineairRing> rings = new List<LineairRing>();
foreach (OsmSharp.IO.Xml.Kml.v2_1.boundaryType geo in boundary)
{
rings.Add(KmlFeatureStreamSource.ConvertLinearRing(geo.LinearRing).Geometry as LineairRing);
}
return rings;
}
示例3: OsmStreamFilterPoly
/// <summary>
/// Creates a new polygon filter.
/// </summary>
public OsmStreamFilterPoly(OsmSharp.Geo.Geometries.LineairRing poly)
: base()
{
if (poly == null) { throw new ArgumentNullException("poly"); }
_poly = poly;
_box = new GeoCoordinateBox(poly.Coordinates);
this.Meta.Add("poly", OsmSharp.Geo.Streams.GeoJson.GeoJsonConverter.ToGeoJson(_poly));
}
示例4: GenerateImmidiateTurn
/// <summary>
/// Generates an immidiate turn.
/// </summary>
/// <param name="instruction"></param>
/// <param name="firstStreetCountTo"></param>
/// <param name="firstStreetTo"></param>
/// <param name="firstDirection"></param>
/// <param name="secondStreetTo"></param>
/// <param name="secondDirection"></param>
/// <returns></returns>
public Instruction GenerateImmidiateTurn(Instruction instruction,
int firstStreetCountTo,
List<KeyValuePair<string, string>> firstStreetTo,
OsmSharp.Tools.Math.Geo.Meta.RelativeDirection firstDirection,
List<KeyValuePair<string, string>> secondStreetTo,
RelativeDirection secondDirection)
{
instruction.Text = string.Format("GenerateImmidiateTurn:{0}_{1}_{2}_{3}",
firstStreetCountTo, firstDirection,
firstDirection.ToString(),
secondDirection.ToString());
return instruction;
}
示例5: ConvertPolygon
/// <summary>
/// Converts a polygon.
/// </summary>
/// <param name="polygon"></param>
/// <returns></returns>
private static Polygon ConvertPolygon(OsmSharp.Xml.Kml.v2_0_response.Polygon polygon)
{
LineairRing inner = KmlGeoStreamSource.ConvertLinearRing(polygon.innerBoundaryIs.LinearRing);
LineairRing outer = KmlGeoStreamSource.ConvertLinearRing(polygon.outerBoundaryIs.LinearRing);
return new Polygon(outer, new LineairRing[] { inner });
}
示例6: ConvertPoint
/// <summary>
/// Converts a point into an oms object.
/// </summary>
/// <param name="point"></param>
/// <returns></returns>
private static Point ConvertPoint(OsmSharp.Xml.Kml.v2_1.PointType point)
{
// convert the coordiantes.
IList<GeoCoordinate> coordinates = KmlGeoStreamSource.ConvertCoordinates(point.coordinates);
// create the point.
Point pointGeometry = new Point(coordinates[0]);
pointGeometry.Attributes = new SimpleGeometryAttributeCollection();
if (point.targetId != null) { pointGeometry.Attributes.Add("targetId", point.targetId); }
pointGeometry.Attributes.Add("altitude", point.altitudeMode);
if (point.extrude) { pointGeometry.Attributes.Add("extrude", point.extrude); }
if (point.id != null) { pointGeometry.Attributes.Add("id", point.id); }
return pointGeometry;
}
示例7: ConvertMultiPolygon
/// <summary>
/// Converts a multipolygon into osm objects.
/// </summary>
/// <param name="multiPolygon"></param>
/// <returns></returns>
private static MultiPolygon ConvertMultiPolygon(OsmSharp.Xml.Kml.v2_0_response.MultiPolygon multiPolygon)
{
return new MultiPolygon(new Polygon[] { KmlGeoStreamSource.ConvertPolygon(multiPolygon.Polygon) });
}
示例8: ConvertMultiPoint
/// <summary>
/// Converts a multipoint to osm objects.
/// </summary>
/// <param name="multiPoint"></param>
/// <returns></returns>
private static MultiPoint ConvertMultiPoint(OsmSharp.Xml.Kml.v2_0_response.MultiPoint multiPoint)
{
return new MultiPoint(new Point[] { KmlGeoStreamSource.ConvertPoint(multiPoint.Point) });
}
示例9: ConvertMultiLineString
/// <summary>
/// Converts a multilinestring to osm objects.
/// </summary>
/// <param name="multiLineString"></param>
/// <returns></returns>
private static MultiLineString ConvertMultiLineString(OsmSharp.Xml.Kml.v2_0_response.MultiLineString multiLineString)
{
return new MultiLineString(new LineString[] { KmlGeoStreamSource.ConvertLineString(multiLineString.LineString) });
}
示例10: ConvertLineString
/// <summary>
/// Converts a line string into an osm object.
/// </summary>
/// <param name="lineString"></param>
/// <returns></returns>
private static LineString ConvertLineString(OsmSharp.Xml.Kml.v2_1.LineStringType lineString)
{
// convert the coordinates.
IList<GeoCoordinate> coordinates = KmlGeoStreamSource.ConvertCoordinates(lineString.coordinates);
// create the ring.
LineString lineStringGeometry = new LineString(coordinates);
lineStringGeometry.Attributes = new SimpleGeometryAttributeCollection();
lineStringGeometry.Attributes.Add("id", lineString.id);
return lineStringGeometry;
}
示例11: ConvertLinearRing
/// <summary>
/// Converts a lineairring into an osm object.
/// </summary>
/// <param name="linearRing"></param>
/// <returns></returns>
private static LineairRing ConvertLinearRing(OsmSharp.Xml.Kml.v2_0_response.LinearRing linearRing)
{
// convert the coordinates.
IList<GeoCoordinate> coordinates = KmlGeoStreamSource.ConvertCoordinates(linearRing.coordinates);
// create the ring.
LineairRing ring = new LineairRing(coordinates);
ring.Attributes = new SimpleGeometryAttributeCollection();
ring.Attributes.Add("id", linearRing.id);
return ring;
}
示例12: ConvertWay
/// <summary>
/// Converts a PBF way into an OsmSharp-way.
/// </summary>
/// <param name="block"></param>
/// <param name="way"></param>
/// <returns></returns>
internal OsmSharp.Osm.Way ConvertWay(PrimitiveBlock block, OsmSharp.Osm.PBF.Way way)
{
var simpleWay = new OsmSharp.Osm.Way();
simpleWay.Id = way.id;
simpleWay.Nodes = new List<long>(way.refs.Count);
long node_id = 0;
for (int node_idx = 0; node_idx < way.refs.Count; node_idx++)
{
node_id = node_id + way.refs[node_idx];
simpleWay.Nodes.Add(node_id);
}
simpleWay.Tags = new TagsCollection(way.keys.Count);
if (way.keys.Count > 0)
{
for (int tag_idx = 0; tag_idx < way.keys.Count; tag_idx++)
{
string key = Encoding.UTF8.GetString(block.stringtable.s[(int)way.keys[tag_idx]]);
string value = Encoding.UTF8.GetString(block.stringtable.s[(int)way.vals[tag_idx]]);
simpleWay.Tags.Add(new Tag(key, value));
}
}
if (way.info != null)
{ // add the metadata if any.
simpleWay.ChangeSetId = way.info.changeset;
simpleWay.TimeStamp = Utilities.FromUnixTime((long)way.info.timestamp *
(long)block.date_granularity);
simpleWay.UserId = way.info.uid;
simpleWay.UserName = Encoding.UTF8.GetString(block.stringtable.s[way.info.user_sid]);
simpleWay.Version = (ulong)way.info.version;
}
simpleWay.Visible = true;
return simpleWay;
}
示例13: ConvertRelation
/// <summary>
/// Converts a PBF way into an OsmSharp-relation.
/// </summary>
/// <param name="block"></param>
/// <param name="relation"></param>
/// <returns></returns>
internal OsmSharp.Osm.Relation ConvertRelation(PrimitiveBlock block, OsmSharp.Osm.PBF.Relation relation)
{
var simpleRelation = new OsmSharp.Osm.Relation();
simpleRelation.Id = relation.id;
if (relation.types.Count > 0)
{
simpleRelation.Members = new List<OsmSharp.Osm.RelationMember>();
long member_id = 0;
for (int member_idx = 0; member_idx < relation.types.Count; member_idx++)
{
member_id = member_id + relation.memids[member_idx];
string role = Encoding.UTF8.GetString(
block.stringtable.s[relation.roles_sid[member_idx]]);
var member = new OsmSharp.Osm.RelationMember();
member.MemberId = member_id;
member.MemberRole = role;
switch (relation.types[member_idx])
{
case Relation.MemberType.NODE:
member.MemberType = OsmSharp.Osm.OsmGeoType.Node;
break;
case Relation.MemberType.WAY:
member.MemberType = OsmSharp.Osm.OsmGeoType.Way;
break;
case Relation.MemberType.RELATION:
member.MemberType = OsmSharp.Osm.OsmGeoType.Relation;
break;
}
simpleRelation.Members.Add(member);
}
}
simpleRelation.Tags = new TagsCollection(relation.keys.Count);
if (relation.keys.Count > 0)
{
for (int tag_idx = 0; tag_idx < relation.keys.Count; tag_idx++)
{
string key = Encoding.UTF8.GetString(block.stringtable.s[(int)relation.keys[tag_idx]]);
string value = Encoding.UTF8.GetString(block.stringtable.s[(int)relation.vals[tag_idx]]);
simpleRelation.Tags.Add(new Tag(key, value));
}
}
if (relation.info != null)
{ // read metadata if any.
simpleRelation.ChangeSetId = relation.info.changeset;
simpleRelation.TimeStamp = Utilities.FromUnixTime((long)relation.info.timestamp *
(long)block.date_granularity);
simpleRelation.UserId = relation.info.uid;
simpleRelation.UserName = Encoding.UTF8.GetString(block.stringtable.s[relation.info.user_sid]);
simpleRelation.Version = (ulong)relation.info.version;
}
simpleRelation.Visible = true;
return simpleRelation;
}
示例14: _mapView_MapInitialized
/// <summary>
/// Called when the map was first initialized.
/// </summary>
/// <param name="mapView">Map view.</param>
/// <param name="newZoom">New zoom.</param>
/// <param name="newTilt">New tilt.</param>
/// <param name="newCenter">New center.</param>
private void _mapView_MapInitialized(OsmSharp.UI.IMapView mapView, float newZoom, OsmSharp.Units.Angle.Degree newTilt, GeoCoordinate newCenter)
{
// make sure the center marker stays in place from now on.
_centerMarker.MoveWithMap = false;
}
示例15: DoSolve
/// <summary>
/// Solves the problem using a GA.
/// </summary>
/// <param name="problem"></param>
/// <returns></returns>
protected override IRoute DoSolve(OsmSharp.Tools.Math.TSP.Problems.IProblem problem)
{
//int population_size = 10;
//if (problem.Size < 100)
//{
// population_size = System.Math.Max(problem.Size * 3, 10);
// if (problem.Size < 10)
// {
// population_size = 1;
// }
//}
//if (problem.Size < 1000)
//{
// population_size = problem.Size / 4;
//}
// create the settings.
SolverSettings settings = new SolverSettings(
_stagnation_count,
_population,
1000000000,
_eltism,
_cross,
_mutation);
//List<IMutationOperation<List<int>, GeneticProblem, Fitness>> mutators = new List<IMutationOperation<int,GeneticProblem,Fitness>>();
////mutators.Add(new DefaultMutationOperation());
////mutators.Add(new BestPlacementMutationOperation());
//mutators.Add(new BestDetailedPlacementMutationOperation());
//List<double> probabilities = new List<double>();
//probabilities.Add(1);
////probabilities.Add(0.5);
////probabilities.Add(0.3);
//CombinedMutation<List<int>, GeneticProblem, Fitness> mutation = new CombinedMutation<int,GeneticProblem,Fitness>(
// StaticRandomGenerator.Get(),
// mutators,
// probabilities);
////SequentialContructiveCrossoverOperator cross_over = new SequentialContructiveCrossoverOperator();
//BestDetailedPlacementCrossOverOperation cross_over = new BestDetailedPlacementCrossOverOperation();
////BestPlacementCrossOverOperation cross_over = new BestPlacementCrossOverOperation();
////EdgeRecombinationCrossOverOperation cross_over = new EdgeRecombinationCrossOverOperation();
//BestPlacementGenerationOperation generation = new BestPlacementGenerationOperation();
////RandomGenerationOperation generation = new RandomGenerationOperation();
ISelector<List<int>, GeneticProblem, Fitness> selector = new RandomSelector<List<int>, GeneticProblem, Fitness>();
//ISelector<List<int>, GeneticProblem, Fitness> selector = new TournamentBasedSelector<List<int>, GeneticProblem, Fitness>(75, 0.01);
solver =
new Solver<List<int>, GeneticProblem, Fitness>(
new GeneticProblem(problem),
settings,
selector,
_mutation_operation,
_cross_over_operation,
_generation_operation,
new FitnessCalculator(),
true, false);
solver.NewFittest += new Solver<List<int>, GeneticProblem, Fitness>.NewFittestDelegate(solver_NewFittest);
solver.NewGeneration += new Solver<List<int>, GeneticProblem, Fitness>.NewGenerationDelegate(solver_NewGeneration);
List<int> result = new List<int>(solver.Start(null).Genomes);
result.Insert(0, 0);
return new SimpleAsymmetricRoute(result, true);
}