Пример #1
0
        public double risk(double lng, double lat, AirCondition airCondition)
        {
            CoorTransferer coorTransferer = new CoorTransferer(20);

            double[] coor = coorTransferer.Nautica2xy(lng, lat);

            PollutedPoint pollutedPoint = new PollutedPoint((int)coor[0], (int)coor[1]);

            foreach (PollutionSource pollutionSource in this.PollutionSources)
            {
                double sourceLng = pollutionSource.X;
                double sourceLat = pollutionSource.Y;

                double[] source = coorTransferer.Nautica2xy(sourceLng, sourceLat);

                pollutionSource.X = source[0];
                pollutionSource.Y = source[1];

                // 加载外部 python 脚本文件.
                ScriptRuntime pyRumTime = Python.CreateRuntime();
                dynamic       obj       = pyRumTime.UseFile("t.py");
                obj.GetArbitraryC(pollutedPoint, airCondition, pollutionSource);    // python脚本计算污染点的浓度值,并将计算结果返回给对象的污染物浓度属性

                // 使用后还原
                pollutionSource.X = sourceLng;
                pollutionSource.Y = sourceLat;
            }

            return(pollutedPoint.Concentration);
        }
Пример #2
0
        public void mock(AirCondition airCondition)
        {
            this.Initialize();
            CoorTransferer coorTransferer = new CoorTransferer(20);

            foreach (PollutionSource pollutionSource in this.PollutionSources)
            {
                double lng = pollutionSource.X;
                double lat = pollutionSource.Y;

                double[] source = coorTransferer.Nautica2xy(lng, lat);

                pollutionSource.X = source[0];
                pollutionSource.Y = source[1];

                int x = (int)source[0];
                int y = (int)source[1];

                int width = 500;
                int step  = 50;

                for (int dx = x - width; dx <= x + width; dx += step)
                {
                    for (int dy = y - width; dy <= y + width; dy += step)
                    {
                        // 加载外部 python 脚本文件.
                        ScriptRuntime pyRumTime = Python.CreateRuntime();
                        dynamic       obj       = pyRumTime.UseFile("t.py");
                        PollutedPoint newPoint;

                        if (PointExist(dx, dy) < 0)
                        {
                            newPoint = new PollutedPoint(dx, dy);
                            obj.GetArbitraryC(newPoint, airCondition, pollutionSource);    // python脚本计算污染点的浓度值,并将计算结果返回给对象的污染物浓度属性
                            pointsXY.Add(newPoint);
                        }
                        else
                        {
                            newPoint = pointsXY[PointExist(dx, dy)];
                            obj.GetArbitraryC(newPoint, airCondition, pollutionSource);    // python脚本计算污染点的浓度值,并将计算结果返回给对象的污染物浓度属性
                        }
                    }
                }

                // 使用后还原
                pollutionSource.X = lng;
                pollutionSource.Y = lat;
            }

            foreach (PollutedPoint point in pointsXY)
            {
                PollutedPointMap newPointMap = new PollutedPointMap(point);
                PollutedPoints.Add(newPointMap);
            }

            this.SaveChanges();
        }