Exemplo n.º 1
0
        // May throw: parseGeoJson may throw if geoJsonFile is not conformant.
        public MkGeoMap(string geoJsonFile)
        {
            MkGeoMultiMap multi = new MkGeoMultiMap(geoJsonFile);

            if (multi.Count != 1)
            {
                throw new Exception("Only support geojson with one feature (region)");
            }
            var keys = multi.Keys;

            _name = keys.ElementAt(0);
            if (multi[_name].size != 1)
            {
                throw new Exception("Only support geojson feature of Polygon (as opposed to MultiPolygon");
            }
            _polygon = multi[_name][0];
        }
Exemplo n.º 2
0
        isInside(MkGeoMultiMap country, Vertex point, double borderMargin)
        {
            HashSet <string> borders = new HashSet <string>();
            HashSet <string> ins     = new HashSet <string>();
            HashSet <string> outs    = new HashSet <string>();
            List <(string name, double buffer)> buffers = new List <(string name, double buffer)>();
            Dictionary <string, List <(string name, double buffer)> > ret = new Dictionary <string, List <(string name, double buffer)> >();

            foreach (KeyValuePair <string, MultiPolygon> kv in country)
            {
                string       province  = kv.Key;
                MultiPolygon multiPoly = kv.Value;
                double       minBuffer = Double.PositiveInfinity;
                foreach (Polygon poly in multiPoly)
                {
                    LinearRing ring = poly.outerRing;
                    var        res  = isInside(point, ring, borderMargin);
                    if (res.inout == 0)
                    {
                        borders.Add(province);
                    }
                    else if (res.inout == -1)
                    {
                        ins.Add(province);
                    }
                    else if (res.inout == 1)
                    {
                        outs.Add(province);
                    }
                    if (Math.Abs(res.radius) < Math.Abs(minBuffer))
                    {
                        minBuffer = res.radius;
                    }
                }
                if (Math.Abs(minBuffer) < Double.PositiveInfinity)
                {
                    buffers.Add((name: province, buffer: minBuffer));
                }
            }
            HashSet <string> prov = new HashSet <string>(ins);

            prov.UnionWith(borders);
            foreach (string p in prov)
            {
                if (ins.Contains(p))
                {
                    ret["in"] = new List <(string name, double buffer)>();
                    ret["in"].Add((name: p, buffer: 0.0));
                }
                else if (borders.Contains(p))
                {
                    if (ret.ContainsKey("border"))
                    {
                        ret["border"].Add((name: p, buffer: 0.0));
                    }
                    else
                    {
                        ret["border"] = new List <(string name, double buffer)>();
                        ret["border"].Add((name: p, buffer: 0.0));
                    }
                }
            }
            if (buffers.Count > 0)
            {
                ret["buffer"] = buffers;
            }
            Dictionary <string, (string name, double buffer)[]> retn = new Dictionary <string, (string name, double buffer)[]>();