コード例 #1
0
ファイル: ExamplesDfs2.cs プロジェクト: DHI/MIKECore-Examples
        /// <summary>
        /// Example of how to resample a dfs2 file in x/y space
        /// </summary>
        /// <param name="inputFilename">Path and name of the file to resample</param>
        /// <param name="outputFilename">Path and name of the new file to create</param>
        /// <param name="xCount">Number of cells in x-direction</param>
        /// <param name="yCount">Number of cells in y-direction</param>
        public static void Resample(string inputFilename, string outputFilename, int xCount, int yCount)
        {
            // Load dfs2 file
            Dfs2File     dfs2File = DfsFileFactory.Dfs2FileOpen(inputFilename);
            IDfsAxisEqD2 axis     = (IDfsAxisEqD2)dfs2File.SpatialAxis;

            // Create reprojector
            Dfs2Reprojector reproj = new Dfs2Reprojector(dfs2File, outputFilename);

            // scale change
            double dxScale = (double)axis.XCount / xCount;
            double dyScale = (double)axis.YCount / yCount;

            // Calculate new lon/lat origin - center of lower left cell
            Cartography cart = new Cartography(dfs2File.FileInfo.Projection.WKTString, dfs2File.FileInfo.Projection.Longitude, dfs2File.FileInfo.Projection.Latitude, dfs2File.FileInfo.Projection.Orientation);
            // Change in center of lower left cell
            double dxOrigin = 0.5 * axis.Dx * (dxScale - 1);
            double dyOrigin = 0.5 * axis.Dy * (dyScale - 1);

            cart.Xy2Geo(dxOrigin, dyOrigin, out double lonOrigin, out double latOrigin);

            // Set new target
            reproj.SetTarget(dfs2File.FileInfo.Projection.WKTString, lonOrigin, latOrigin, dfs2File.FileInfo.Projection.Orientation, xCount, 0, axis.Dx * dxScale, yCount, 0, axis.Dy * dyScale);
            reproj.Interpolate = true;
            // Create new file
            reproj.Process();
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            var theView = new UIView();
            var theBttn = new UIButton();

            Cartography.Constrain(theView, theBttn, (view1, view2) =>
            {
                var z = (view1.Width == view2.Width + 15);
                z     = (view1.Height == view2.Height * 3);
            });
        }
コード例 #3
0
        private void ProcessLayerVersion(string sql, LayerVersion lv, Cartography aggregateLevel = null)
        {
            List <object> fieldList = new List <object>();

            fieldList.Add(lv.Layer.Id.Value);
            fieldList.Add(lv.Id.Value);
            if (aggregateLevel == null)
            {
                fieldList.Add("null");
            }
            else
            {
                fieldList.Add("cai_cartography_id");
            }
            fieldList.Add("cai_id");
            fieldList.Add("cai_urbanity");
            fieldList.Add("id");
            // Valores
            bool   useAggregateFunction = (aggregateLevel != null);
            string allValues            = calculateAllValuesField(lv, useAggregateFunction);

            fieldList.Add(allValues);
            // Etiquetas
            string allVersionValueLabels = calculateAllVersionValueLabelId(lv, useAggregateFunction, aggregateLevel);

            fieldList.Add(allVersionValueLabels);

            // Descripción
            if (useAggregateFunction && lv.DatasetCaptionColumn != null && lv.DatasetCaptionColumn.Aggregation == AggregationEnum.Transpose && useAggregateFunction)
            {
                fieldList.Add("null");
            }
            else
            {
                fieldList.Add(LviFunctions.GetRichColumn(lv.DatasetCaption, lv.DatasetCaptionColumn));
            }
            // Summary
            if (useAggregateFunction && lv.SummaryColumn != null && lv.SummaryColumn.Aggregation == AggregationEnum.Transpose)
            {
                fieldList.Add("0");
            }
            else
            {
                fieldList.Add(LviFunctions.GetRichColumn(lv.Summary, lv.SummaryColumn));
            }

            // featureId
            if (lv.Dataset.DatasetType == DatasetTypeEnum.Shapes ||
                lv.Dataset.DatasetType == DatasetTypeEnum.Locations)
            {
                fieldList.Add(((long)lv.Dataset.Id.Value * 0x100000000) + "+id");
            }
            else
            {
                fieldList.Add("cai_id");
            }

            fieldList.Add(SpecialColumnEnum.AreaM2);
            fieldList.Add(SpecialColumnEnum.People);
            fieldList.Add(SpecialColumnEnum.Household);
            fieldList.Add(SpecialColumnEnum.Children);
            if (lv.Dataset.DatasetType == DatasetTypeEnum.Shapes)
            {
                fieldList.Add("Envelope(geometry)");
                fieldList.Add("id");
                fieldList.Add("area_m2");
                fieldList.Add("centroid");
            }
            else if (lv.Dataset.DatasetType == DatasetTypeEnum.Locations)
            {
                string point = "POINT(" + lv.Dataset.LatitudeColumn.Field + ", " +
                               lv.Dataset.LongitudeColumn.Field + ")";
                fieldList.Add("Envelope(" + point + ")");
                fieldList.Add(null);
                fieldList.Add(null);
                fieldList.Add(point);
            }
            else if (lv.Dataset.DatasetType == DatasetTypeEnum.Data)
            {
                fieldList.Add("Envelope(cai_geometry)");
                fieldList.Add(null);
                fieldList.Add(null);
                fieldList.Add("cai_centroid");
            }
            else
            {
                throw new Exception("Invalid dataset type.");
            }

            int joinShapesId;

            if (lv.Dataset.DatasetType == DatasetTypeEnum.Shapes)
            {
                joinShapesId = lv.Dataset.Id.Value;
            }
            else
            {
                joinShapesId = 0;
            }
            string select = DatasetTable.GetSelectValuesSql(lv.Dataset, fieldList, aggregateLevel);

            select += LviFunctions.AppendGeometryNotNullCondition(lv);

            rowsAffected += medea.context.Data.Session.SqlActions.ExecuteNonQuery(sql + select, true);
        }
コード例 #4
0
        private string calculateAllVersionValueLabelId(LayerVersion lv, bool useAggregateFunction, Cartography level)
        {
            List <string> ret = new List <string>();

            foreach (var v in lv.Variables)
            {
                if (v.Use(useAggregateFunction))
                {
                    string value = LviFunctions.calculateValueField(v);
                    ret.Add(LviFunctions.calculateVersionValueLabelId(v, value, level));
                    ret.Add("'\t'");
                }
            }
            ret.RemoveAt(ret.Count - 1);
            return("CONCAT(" + String.Join(",", ret) + ")");
        }