Ejemplo n.º 1
0
        /// <summary>
        /// </summary>
        /// <param name="line">the line to buffer</param>
        /// <param name="startWidth">the buffer width at the start of the line</param>
        /// <param name="endWidth">the buffer width at the end of the line</param>
        /// <returns>The variable-width buffer polygon</returns>
        public static IGeometry Buffer(ILineString line, double startWidth,
                                       double endWidth)
        {
            var width = Interpolate(line, startWidth, endWidth);
            var vb    = new VariableWidthBuffer(line, width);

            return(vb.GetResult());
        }
Ejemplo n.º 2
0
        public object Search(string from, string to, int radius)
        {
            HttpClient webservice = new HttpClient();

            string url = "https://maps.googleapis.com/maps/api/directions/json?origin=" + from + "&destination=" + to + "&key=AIzaSyDIR_Gt9qJxpvTgCr9z-wfCVFTKPjGs_8w";

            //Debug.WriteLine(postData);

            HttpResponseMessage response = webservice.GetAsync(url).Result;

            /*  */
            GoogleDirectionClass objRoutes = JsonConvert.DeserializeObject <GoogleDirectionClass>(response.Content.ReadAsStringAsync().Result);

            if (objRoutes.routes.Count > 0)
            {
                string encodedPoints = objRoutes.routes[0].overview_polyline.points;

                List <Models.Location> lstDecodedPoints = FnDecodePolylinePoints(encodedPoints);
                //convert list of location point to array of latlng type
                LatLngNew[]  latLngPoints = new LatLngNew[lstDecodedPoints.Count];
                Coordinate[] ss           = new Coordinate[lstDecodedPoints.Count];

                int index = 0;
                foreach (Models.Location loc in lstDecodedPoints)
                {
                    latLngPoints[index] = new LatLngNew(loc.lat, loc.lng);
                    ss[index]           = new Coordinate(loc.lat, loc.lng);
                    index++;
                }
                //TODO: do bd....
                double searchRadios = (double)radius / 37;

                var lineString   = new LineString(ss);
                var buffer       = VariableWidthBuffer.Buffer(lineString, searchRadios, searchRadios);
                var bArray       = buffer.Coordinates;
                var bArrayLength = buffer.Coordinates.Length;
                double[,] pArray = new double[bArrayLength, 2];
                for (int i = 0; i < bArrayLength; i++)
                {
                    pArray[i, 0] = bArray[i].X;
                    pArray[i, 1] = bArray[i].Y;
                }
                GoogleReturnObj returnObj = new GoogleReturnObj()
                {
                    PolyLinePoints = latLngPoints.ToList(),
                    Source         = new Area()
                    {
                        Pos = new LatLngNew(objRoutes.routes[0].legs[0].start_location.lat, objRoutes.routes[0].legs[0].start_location.lng), Name = from
                    },
                    Destination = new Area()
                    {
                        Pos = new LatLngNew(objRoutes.routes[0].legs[0].end_location.lat, objRoutes.routes[0].legs[0].end_location.lng), Name = to
                    },
                    Points = pArray
                };

                var s = new { convert = buffer, coordinates = latLngPoints, coords = buffer.Coordinates.Select(x => new LatLngNew(x.X, x.Y)), darr = buffer.Coordinates.Select(d => new double[] { d.X, d.Y }) };
                return(returnObj);
            }
            return(null);
        }