private static Collection <LocationCollection> GetPoints(byte[] content, ICoordinateValueConverter coordinateConverter) { int numberOfParts = BitConverter.ToInt32(content, 36); int numberOfPoints = BitConverter.ToInt32(content, 40); int startPoints = 44 + 4 * numberOfParts; Collection <LocationCollection> collection = new Collection <LocationCollection>(); int pointsCount, partFirstPointIndex, startPoint; for (int partIndex = 0; partIndex < numberOfParts; partIndex++) { partFirstPointIndex = BitConverter.ToInt32(content, 44 + 4 * partIndex); // Each point is represented by x,y double coordinates -- 16 bytes startPoint = startPoints + partFirstPointIndex * 16; if (partIndex < numberOfParts - 1) { pointsCount = BitConverter.ToInt32(content, 44 + 4 * (partIndex + 1)) - partFirstPointIndex; } else { pointsCount = numberOfPoints - partFirstPointIndex; } LocationCollection locations = GetPoints(content, startPoint, pointsCount, coordinateConverter); collection.Add(locations); } return(collection); }
private static LocationRect GetBoundingRect(byte[] boundingBox, ICoordinateValueConverter coordinateConverter) { double west = BitConverter.ToDouble(boundingBox, 0); double south = BitConverter.ToDouble(boundingBox, 8); double east = BitConverter.ToDouble(boundingBox, 16); double north = BitConverter.ToDouble(boundingBox, 24); Location northwest = new Location(north, west); if (coordinateConverter != null) { northwest = coordinateConverter.Convert(northwest); } Location southeast = new Location(south, east); if (coordinateConverter != null) { southeast = coordinateConverter.Convert(southeast); } return(new LocationRect(northwest, southeast)); }
private static void CreatePoint(byte[] content, MapShapeModelCollection shapeModels, int pointOffset, ICoordinateValueConverter coordinateConverter) { double longitude = BitConverter.ToDouble(content, pointOffset); double latitude = BitConverter.ToDouble(content, pointOffset + 8); var location = new Location(latitude, longitude); // NOTE: Optionally allow the user to re-project coordinates to different system. if (coordinateConverter != null) { location = coordinateConverter.Convert(location); } shapeModels.Add(new MapPointModel() { Location = location }); }
private static LocationCollection GetPoints(byte[] content, int startPoint, int count, ICoordinateValueConverter coordinateConverter) { int point; double longitude, latitude; Location location; LocationCollection locations = new LocationCollection(); for (int pointIndex = 0; pointIndex < count; pointIndex++) { point = startPoint + pointIndex * 16; longitude = BitConverter.ToDouble(content, point); latitude = BitConverter.ToDouble(content, point + 8); location = new Location() { Latitude = latitude, Longitude = longitude }; // NOTE: Optionally allow the user to re-project coordinates to different system. if (coordinateConverter != null) { location = coordinateConverter.Convert(location); } locations.Add(location); } return(locations); }
private static void CreatePolygon(byte[] content, MapShapeModelCollection shapeModels, ICoordinateValueConverter coordinateConverter) { shapeModels.Add(new MapPolygonModel() { Locations = GetPoints(content, coordinateConverter) }); }
private static void CreatePoints(byte[] content, MapShapeModelCollection shapeModels, ICoordinateValueConverter coordinateConverter) { int numberOfPoints = BitConverter.ToInt32(content, 36); int pointOffset; for (int i = 0; i < numberOfPoints; i++) { // NOTE: Points field starts at Byte 40 and consists of [x,y] double pair (16 bytes) pointOffset = 40 + 16 * i; CreatePoint(content, shapeModels, pointOffset, coordinateConverter); } }