예제 #1
0
        private void AddMapLayer()
        {
            // Create the MapPrinterLayer and set the position
            MapPrinterLayer mapPrinterLayer = new MapPrinterLayer();

            mapPrinterLayer.MapUnit        = GeographyUnit.Meter;
            mapPrinterLayer.MapExtent      = new RectangleShape(-20026376.39, 20048966.10, 20026376.39, -20048966.10);
            mapPrinterLayer.BackgroundMask = new AreaStyle(new GeoPen(GeoColors.Black, 1));
            mapPrinterLayer.Open();

            // Set the maps position slightly below the pages center and 8 inches wide and 7 inches tall
            RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);

            mapPrinterLayer.SetPosition(8, 7, pageBoundingbox.GetCenterPoint().X, pageBoundingbox.GetCenterPoint().Y + 1, PrintingUnit.Inch);

            // Setup the intial extent and ensure they snap to the default ZoomLevel
            ZoomLevelSet zoomLevelSet = new ZoomLevelSet();

            mapPrinterLayer.MapExtent = MapUtil.ZoomToScale(zoomLevelSet.ZoomLevel03.Scale, new RectangleShape(-20026376.39, 20048966.10, 20026376.39, -20048966.10), mapPrinterLayer.MapUnit, (float)mapPrinterLayer.GetBoundingBox().Width, (float)mapPrinterLayer.GetBoundingBox().Height);

            // This ThinkGeo Cloud test key is exclusively for demonstration purposes and is limited to requesting base map
            // tiles only. Do not use it in your own applications, as it may be restricted or disabled without prior notice.
            // Please visit https://cloud.thinkgeo.com to create a free key for your own use.
            //ThinkGeoCloudRasterMapsLayer worldMapKitLayer = new ThinkGeoCloudRasterMapsLayer("itZGOI8oafZwmtxP-XGiMvfWJPPc-dX35DmESmLlQIU~", "bcaCzPpmOG6le2pUz5EAaEKYI-KSMny_WxEAe7gMNQgGeN9sqL12OA~~");
            //worldMapKitLayer.TileCache = null;
            //mapPrinterLayer.Layers.Add(worldMapKitLayer);
            ShapeFileFeatureLayer backgroundLayer = new ShapeFileFeatureLayer(@"data/Countries02_3857.shp", FileAccess.Read);

            backgroundLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            backgroundLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle    = AreaStyle.CreateSimpleAreaStyle(GeoColors.White, GeoColors.Black);
            mapPrinterLayer.Layers.Add(backgroundLayer);

            // Setup the Countries mapping layer
            ShapeFileFeatureLayer shapefileFeatureLayer = new ShapeFileFeatureLayer(@"data/Countries02_3857.shp", FileAccess.Read);

            shapefileFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            //Create the class break style for countries less than 70 million
            ClassBreakStyle classBreakStyle = new ClassBreakStyle("POP_CNTRY");

            // Create the style and class break for countries with greater and 70 million
            AreaStyle hatchAreaStyle = new AreaStyle(new GeoSolidBrush(GeoColor.FromArgb(100, GeoColors.Green)));

            classBreakStyle.ClassBreaks.Add(new ClassBreak(70000000, hatchAreaStyle));

            // Add the class break style to the layer
            shapefileFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakStyle);

            // Add the new country layer to the MapPrinterLayer
            mapPrinterLayer.Layers.Add(shapefileFeatureLayer);

            // Add the MapPrinterLayer to the PrinterInteractiveOverlay
            PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];

            printerInteractiveOverlay.PrinterLayers.Add("MapLayer", mapPrinterLayer);
        }
        private void AddMapLayer()
        {
            // Create the MapPrinterLayer and set the position
            MapPrinterLayer mapPrinterLayer = new MapPrinterLayer();

            //Map Printer Layer is in feet (State Plane Texas North Central Feet NAD83)
            mapPrinterLayer.MapUnit = GeographyUnit.Feet;
            //Set the extent of the MapPrinterLayer with world coordinates.
            RectangleShape currentExtent = new RectangleShape(2276456, 6897886, 2280391, 6895437);

            mapPrinterLayer.MapExtent      = currentExtent;
            mapPrinterLayer.BackgroundMask = new AreaStyle(new GeoPen(GeoColors.Black, 1));
            mapPrinterLayer.Open();

            // Set the maps position slightly above the page center and 8 inches wide and 7 inches tall
            RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);

            mapPrinterLayer.SetPosition(8, 7, pageBoundingbox.GetCenterPoint().X, pageBoundingbox.GetCenterPoint().Y + 1, PrintingUnit.Inch);

            //Setup the styles for the parcels layer.
            ShapeFileFeatureLayer parcelsLayer = new ShapeFileFeatureLayer(@"..\..\..\Data\Shapefile\parcels.shp", FileAccess.Read);
            //Creates a value style for the parcel type (residential 1, commercial 2, industrial 3).
            ValueStyle typeValueStyle = new ValueStyle();

            typeValueStyle.ColumnName = "PARCELTYPE";
            typeValueStyle.ValueItems.Add(new ValueItem("1", new AreaStyle(new GeoPen(GeoColors.Black), new GeoSolidBrush(GeoColors.PastelGreen))));
            typeValueStyle.ValueItems.Add(new ValueItem("2", new AreaStyle(new GeoPen(GeoColors.Black), new GeoSolidBrush(GeoColors.PastelOrange))));
            typeValueStyle.ValueItems.Add(new ValueItem("3", new AreaStyle(new GeoPen(GeoColors.Black), new GeoSolidBrush(GeoColors.PastelBlue))));
            parcelsLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(typeValueStyle);

            //Creates a value style for affected parcels by new proposal
            ValueStyle affectedValueStyle = new ValueStyle();

            affectedValueStyle.ColumnName = "AFFECTED";
            affectedValueStyle.ValueItems.Add(new ValueItem("YES", new AreaStyle(new GeoPen(GeoColors.DarkGreen, 4), new GeoSolidBrush(GeoColors.Transparent))));
            affectedValueStyle.ValueItems.Add(new ValueItem("D", new AreaStyle(new GeoPen(GeoColors.DarkRed, 4), new GeoSolidBrush(GeoColors.Transparent))));
            parcelsLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(affectedValueStyle);

            //Creates a text style to display tax id of parcels
            TextStyle textStyle = new TextStyle("TAXPIN", new GeoFont("Arial", 12, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColors.Black));

            textStyle.HaloPen = new GeoPen(GeoColors.White, 2);
            parcelsLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(textStyle);
            parcelsLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            // Add the new parcels layer to the MapPrinterLayer
            mapPrinterLayer.Layers.Add(parcelsLayer);

            // Add the MapPrinterLayer to the PrinterInteractiveOverlay
            PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)mapView.InteractiveOverlays["PrintPreviewOverlay"];

            printerInteractiveOverlay.PrinterLayers.Add("MapLayer", mapPrinterLayer);
        }
예제 #3
0
        protected override void DrawCore(GeoCanvas canvas, Collection <SimpleCandidate> labelsInAllLayers)
        {
            if (String.IsNullOrEmpty(projectPath))
            {
                return;
            }
            base.DrawCore(canvas, labelsInAllLayers);

            double         oneToOneScale      = PrinterHelper.GetPointsPerGeographyUnit(canvas.MapUnit);
            RectangleShape currentBoundingBox = GetBoundingBox();

            string drawingText = projectPath;

            if (printerWrapMode == PrinterWrapMode.WrapText)
            {
                float drawingSize = (float)(Font.Size * oneToOneScale / canvas.CurrentScale);
                drawingFont = new GeoFont(Font.FontName, drawingSize, Font.Style);

                drawingText = WrapText(canvas, currentBoundingBox, drawingFont, projectPath);
            }
            else
            {
                // 1st time draw the layer, change the fontsize to match up the boundingBox
                if (lastBoundingBox == null)
                {
                    float drawingSize = font.Size;
                    if (currentBoundingBox.GetWellKnownText() != new RectangleShape().GetWellKnownText())
                    {
                        drawingSize = GetFontSizeByBoundingBox(canvas, Font, drawingText, currentBoundingBox);
                    }
                    drawingFont = new GeoFont(font.FontName, drawingSize, font.Style);

                    drawingSize = (float)(drawingSize / oneToOneScale * canvas.CurrentScale);
                    Font        = new GeoFont(font.FontName, drawingSize, font.Style);
                }
                else
                {
                    // change the boundingBox, change the fontsize to match up the boundingBox
                    if ((Math.Round(lastBoundingBox.Width, 8) != Math.Round(currentBoundingBox.Width, 8)) ||
                        (Math.Round(lastBoundingBox.Height, 8) != Math.Round(currentBoundingBox.Height, 8)))     // Change font size when resize
                    {
                        float drawingSize = GetFontSizeByBoundingBox(canvas, drawingFont, drawingText, currentBoundingBox);
                        drawingFont = new GeoFont(font.FontName, drawingSize, font.Style);

                        drawingSize = (float)(drawingSize / oneToOneScale * canvas.CurrentScale);
                        Font        = new GeoFont(font.FontName, drawingSize, font.Style);
                    }
                    else
                    {
                        float drawingSize = (float)(Font.Size * oneToOneScale / canvas.CurrentScale);
                        drawingFont = new GeoFont(font.FontName, drawingSize, font.Style);
                    }
                }

                lastBoundingBox = currentBoundingBox;
            }

            canvas.DrawTextWithWorldCoordinate(drawingText, drawingFont, TextBrush, currentBoundingBox.GetCenterPoint().X, currentBoundingBox.GetCenterPoint().Y, DrawingLevel.LabelLevel);
        }
예제 #4
0
        private void ZoomToFeatures(IEnumerable <Feature> features, FeatureLayer featureLayer)
        {
            RectangleShape extent        = features.Count() == 1 ? GetBoundingBox(features.FirstOrDefault()) : ExtentHelper.GetBoundingBoxOfItems(features);
            RectangleShape drawingExtent = ExtentHelper.GetDrawingExtent(extent, (float)GisEditor.ActiveMap.ActualWidth, (float)GisEditor.ActiveMap.ActualHeight);
            var            scale         = ExtentHelper.GetScale(drawingExtent, (float)map.ActualWidth, map.MapUnit);

            map.ZoomTo(extent.GetCenterPoint(), scale);
            //GisEditor.UIManager.RefreshPlugins(new RefreshArgs(extent.GetCenterPoint(), "Identify"));
            GisEditor.UIManager.RefreshPlugins(new RefreshArgs(new Tuple <IEnumerable <Feature>, FeatureLayer>(features, featureLayer), "Identify"));
        }
예제 #5
0
        private static RectangleShape SquaredExtent(RectangleShape extent)
        {
            PointShape center = extent.GetCenterPoint();

            double extentWidth  = extent.LowerRightPoint.X - extent.LowerLeftPoint.X;
            double extentHeight = extent.UpperLeftPoint.Y - extent.LowerLeftPoint.Y;

            double halfEdgeLength = (extentWidth > extentHeight) ? extentWidth / 2 : extentHeight / 2;

            PointShape upperLeft  = new PointShape(center.X - halfEdgeLength, center.Y + halfEdgeLength);
            PointShape lowerRight = new PointShape(center.X + halfEdgeLength, center.Y - halfEdgeLength);

            return(new RectangleShape(upperLeft, lowerRight));
        }
        private void AddLogoImage()
        {
            //Load the image to a GeoImage and then create the ImagePrinterLayer using that image
            GeoImage          compassGeoImage   = new GeoImage(@"..\..\..\Resources\Compass.png");
            ImagePrinterLayer imagePrinterLayer = new ImagePrinterLayer(compassGeoImage);

            // Set the imagePrinterLayer position offset from the page center and .75 inches wide and .75 inches tall
            RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);

            imagePrinterLayer.SetPosition(.75, .75, pageBoundingbox.GetCenterPoint().X + 3.5, pageBoundingbox.GetCenterPoint().Y - 2.0, PrintingUnit.Inch);

            // Add the imagePrinterLayer to the PrinterInteractiveOverlay
            PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)mapView.InteractiveOverlays["PrintPreviewOverlay"];

            printerInteractiveOverlay.PrinterLayers.Add("ImageLayer", imagePrinterLayer);
        }
예제 #7
0
        protected override void DrawSampleCore(GeoCanvas canvas, DrawingRectangleF drawingRectangleF)
        {
            RectangleShape rectangle = ToWorldCoordinate(canvas, drawingRectangleF);

            Feature feature = new Feature(rectangle.GetCenterPoint());

            feature.ColumnValues.Add(TextColumnName, "A");
            Feature[] features = new Feature[1] {
                feature
            };
            IconTextStyle style = (IconTextStyle)CloneDeep();

            style.SuppressPartialLabels  = false;
            style.PointPlacement         = PointPlacement.Center;
            style.IsLabelFunctionEnabled = false;
            style.Draw(features, canvas, new Collection <SimpleCandidate>(), new Collection <SimpleCandidate>());
        }
예제 #8
0
        private void AddDataGridLayer()
        {
            // Create the DataGridPrinterLayer
            DataGridPrinterLayer dataGridPrinterLayer = new DataGridPrinterLayer();

            dataGridPrinterLayer.TextFont = new GeoFont("Arial", 8);
            //dataGridPrinterLayer.CellTextJustification = LabelTextJustification.Left;
            dataGridPrinterLayer.TextHorizontalAlignment = PrinterTextHorizontalAlignment.Left;

            // Set the data grid position 4 inches below the page center and 8 inches wide and 2.5 inches tall
            RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);

            dataGridPrinterLayer.SetPosition(8, 2.5, pageBoundingbox.GetCenterPoint().X, pageBoundingbox.GetCenterPoint().Y - 4, PrintingUnit.Inch);

            //Create the data table and columns
            dataGridPrinterLayer.DataTable = new DataTable();
            dataGridPrinterLayer.DataTable.Columns.Add("Country");
            dataGridPrinterLayer.DataTable.Columns.Add("Population");
            dataGridPrinterLayer.DataTable.Columns.Add("CurrencyCode");
            dataGridPrinterLayer.DataTable.Columns.Add("Area");

            // Find all of the countries with a population greater than 70 million
            // and add those items to the data table
            ShapeFileFeatureLayer shapefileFeatureLayer = new ShapeFileFeatureLayer(@"data/Countries02_3857.shp", FileAccess.Read);

            shapefileFeatureLayer.Open();
            Collection <Feature> features = shapefileFeatureLayer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns);

            shapefileFeatureLayer.Close();

            foreach (Feature feature in features)
            {
                double pop = Convert.ToDouble(feature.ColumnValues["Pop_cntry"].ToString());
                if (pop > 70000000)
                {
                    dataGridPrinterLayer.DataTable.Rows.Add(new object[4] {
                        feature.ColumnValues["Cntry_Name"], feature.ColumnValues["Pop_cntry"], feature.ColumnValues["curr_code"], feature.ColumnValues["sqkm"]
                    });
                }
            }

            // Add the DataGridPrinterLayer to the PrinterInteractiveOverlay
            PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];

            printerInteractiveOverlay.PrinterLayers.Add("DataGridLayer", dataGridPrinterLayer);
        }
예제 #9
0
        public static double GetCellWidthByLevel(RectangleShape extent, GeographyUnit extentMapUnit, int level, DistanceUnit returnDistanceUnit)
        {
            PointShape centerPoint = extent.GetCenterPoint();

            PointShape centerLeft  = new PointShape(extent.LowerLeftPoint.X, centerPoint.Y);
            PointShape centerRight = new PointShape(extent.UpperRightPoint.X, centerPoint.Y);
            PointShape centerUpper = new PointShape(centerPoint.X, extent.UpperLeftPoint.Y);
            PointShape centerLower = new PointShape(centerPoint.X, extent.LowerLeftPoint.Y);

            double centerWidth  = centerLeft.GetDistanceTo(centerRight, extentMapUnit, returnDistanceUnit);
            double centerHeight = centerUpper.GetDistanceTo(centerLower, extentMapUnit, returnDistanceUnit);
            double longestEdge  = Math.Max(centerWidth, centerHeight);

            double cellWidth = longestEdge / Math.Sqrt(Math.Pow(4, level - 1));

            return(cellWidth);
        }
예제 #10
0
        public static int GetLevelByCellWidth(RectangleShape extent, GeographyUnit extentMapUnit, double cellWidth, DistanceUnit widthDistanceUnit)
        {
            PointShape centerPoint = extent.GetCenterPoint();

            PointShape centerLeft  = new PointShape(extent.LowerLeftPoint.X, centerPoint.Y);
            PointShape centerRight = new PointShape(extent.UpperRightPoint.X, centerPoint.Y);
            PointShape centerUpper = new PointShape(centerPoint.X, extent.UpperLeftPoint.Y);
            PointShape centerLower = new PointShape(centerPoint.X, extent.LowerLeftPoint.Y);

            double centerWidth  = centerLeft.GetDistanceTo(centerRight, extentMapUnit, widthDistanceUnit);
            double centerHeight = centerUpper.GetDistanceTo(centerLower, extentMapUnit, widthDistanceUnit);

            double longestEdge = Math.Max(centerWidth, centerHeight);

            double level = Math.Round(2 * Math.Log((longestEdge / cellWidth), 4) + 1);

            return((int)level);
        }
        public static RectangleShape GetFixedScaledExtent(RectangleShape bbox, double currentResolution, RectangleShape sourceExtent)
        {
            if (AppMenuUIPlugin.PreserveScale)
            {
                double widthDistanceInPoint  = PrinterHelper.ConvertLength(bbox.Width, PrintingUnit.Inch, PrintingUnit.Point);
                double heightDistanceInPoint = PrinterHelper.ConvertLength(bbox.Height, PrintingUnit.Inch, PrintingUnit.Point);

                double         halfWidthDistanceInMapUnit  = widthDistanceInPoint * .5 * currentResolution;
                double         halfHeightDistanceInMapUnit = heightDistanceInPoint * .5 * currentResolution;
                PointShape     currentCenter    = sourceExtent.GetCenterPoint();
                RectangleShape currentMapExtent = new RectangleShape(currentCenter.X - halfWidthDistanceInMapUnit, currentCenter.Y + halfHeightDistanceInMapUnit, currentCenter.X + halfWidthDistanceInMapUnit, currentCenter.Y - halfHeightDistanceInMapUnit);
                return(currentMapExtent);
            }
            else
            {
                return(sourceExtent);
            }
        }
예제 #12
0
        private void AddGridTitle2()
        {
            //Set the grid tile for approved parcels on top of the right grid.
            RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);
            //For the grid title
            LabelPrinterLayer gridTitleLabelPrinterLayer = new LabelPrinterLayer();

            //Setup the text and the font..
            gridTitleLabelPrinterLayer.Text      = "Parcels In Discussion";
            gridTitleLabelPrinterLayer.Font      = new GeoFont("Arial", 8, DrawingFontStyles.Bold);
            gridTitleLabelPrinterLayer.TextBrush = new GeoSolidBrush(GeoColors.Black);

            // Set the title position so that is it centered on the page one inch from the top and to the right
            gridTitleLabelPrinterLayer.PrinterWrapMode = PrinterWrapMode.AutoSizeText;
            gridTitleLabelPrinterLayer.SetPosition(3, 0.5, new PointShape(2.25, pageBoundingbox.GetCenterPoint().Y - 2.9), PrintingUnit.Inch);

            // Find the PrinterInteractiveOverlay so we can add the new LabelPrinterLayer
            PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)mapView.InteractiveOverlays["PrintPreviewOverlay"];

            printerInteractiveOverlay.PrinterLayers.Add("gridtitle2LabelPrinterLayer", gridTitleLabelPrinterLayer);
        }
예제 #13
0
        private void AddDataGridLayer2()
        {
            // Create the DataGridPrinterLayer for parcels in discussion and place it the right.
            DataGridPrinterLayer dataGridPrinterLayer = new DataGridPrinterLayer();

            dataGridPrinterLayer.TextFont = new GeoFont("Arial", 8);
            dataGridPrinterLayer.TextHorizontalAlignment = PrinterTextHorizontalAlignment.Left;

            // Set the data grid position 4.2 inches below the page center to the right and 3.5 inches wide and 2 inches tall
            RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);

            dataGridPrinterLayer.SetPosition(3.5, 2, 2.25, pageBoundingbox.GetCenterPoint().Y - 4.2, PrintingUnit.Inch);

            //Create the data table and columns
            dataGridPrinterLayer.DataTable = new DataTable();
            dataGridPrinterLayer.DataTable.Columns.Add("TAXPIN");
            dataGridPrinterLayer.DataTable.Columns.Add("LAST_REVIS");
            dataGridPrinterLayer.DataTable.Columns.Add("ACRES");
            dataGridPrinterLayer.DataTable.Columns.Add("CALCULATED");

            // Find all of the parcels that are in discussion and add those items to the data table
            ShapeFileFeatureLayer shapefileFeatureLayer = new ShapeFileFeatureLayer(@"..\..\..\Data\Shapefile\Parcels.shp", FileAccess.Read);

            shapefileFeatureLayer.Open();
            Collection <Feature> features = shapefileFeatureLayer.QueryTools.GetFeaturesByColumnValue("AFFECTED", "D", ReturningColumnsType.AllColumns);

            shapefileFeatureLayer.Close();

            foreach (Feature feature in features)
            {
                dataGridPrinterLayer.DataTable.Rows.Add(new object[4] {
                    feature.ColumnValues["TAXPIN"], feature.ColumnValues["LAST_REVIS"], feature.ColumnValues["ACRES"], feature.ColumnValues["CALCULATED"]
                });
            }

            // Add the DataGridPrinterLayer to the PrinterInteractiveOverlay
            PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)mapView.InteractiveOverlays["PrintPreviewOverlay"];

            printerInteractiveOverlay.PrinterLayers.Add("DataGridLayer2", dataGridPrinterLayer);
        }
예제 #14
0
        private void AddScaleLineLayer()
        {
            // Get the PrinterInteractiveOverlay
            PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)mapView.InteractiveOverlays["PrintPreviewOverlay"];

            // Grab the MapPrinterLayer as we need to pass that into the scaleLinePrinterLayer so it
            // can be synced up to the map itself in real-time
            MapPrinterLayer mapPrinterLayer = (MapPrinterLayer)printerInteractiveOverlay.PrinterLayers["MapLayer"];

            //Create the scaleLinePrinterLayer and pass in the MapPrinterLayer
            ScaleLinePrinterLayer scaleLinePrinterLayer = new ScaleLinePrinterLayer(mapPrinterLayer);

            scaleLinePrinterLayer.MapUnit = GeographyUnit.Feet;

            // Set the scale line position offset from the page center and 1.25 inches wide and .25 inches tall
            RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);

            scaleLinePrinterLayer.SetPosition(1.25, .25, pageBoundingbox.GetCenterPoint().X - 3.25, pageBoundingbox.GetCenterPoint().Y - 2.25, PrintingUnit.Inch);

            // Add the ScaleLinePrinterLayer to the PrinterInteractiveOverlay
            printerInteractiveOverlay.PrinterLayers.Add("ScaleLineLayer", scaleLinePrinterLayer);
        }
예제 #15
0
        private static RectangleShape SquaredExtent(RectangleShape extent)
        {
            PointShape center = extent.GetCenterPoint();

            double extentWidth = extent.LowerRightPoint.X - extent.LowerLeftPoint.X;
            double extentHeight = extent.UpperLeftPoint.Y - extent.LowerLeftPoint.Y;

            double halfEdgeLength = (extentWidth > extentHeight) ? extentWidth / 2 : extentHeight / 2;

            PointShape upperLeft = new PointShape(center.X - halfEdgeLength, center.Y + halfEdgeLength);
            PointShape lowerRight = new PointShape(center.X + halfEdgeLength, center.Y - halfEdgeLength);

            return new RectangleShape(upperLeft, lowerRight);
        }
예제 #16
0
        public static int GetLevelByCellWidth(RectangleShape extent, GeographyUnit extentMapUnit, double cellWidth, DistanceUnit widthDistanceUnit)
        {
            PointShape centerPoint = extent.GetCenterPoint();

            PointShape centerLeft = new PointShape(extent.LowerLeftPoint.X, centerPoint.Y);
            PointShape centerRight = new PointShape(extent.UpperRightPoint.X, centerPoint.Y);
            PointShape centerUpper = new PointShape(centerPoint.X, extent.UpperLeftPoint.Y);
            PointShape centerLower = new PointShape(centerPoint.X, extent.LowerLeftPoint.Y);

            double centerWidth = centerLeft.GetDistanceTo(centerRight, extentMapUnit, widthDistanceUnit);
            double centerHeight = centerUpper.GetDistanceTo(centerLower, extentMapUnit, widthDistanceUnit);

            double longestEdge = Math.Max(centerWidth, centerHeight);

            double level = Math.Round(2 * Math.Log((longestEdge / cellWidth), 4) + 1);

            return (int)level;
        }
예제 #17
0
        public static double GetCellWidthByLevel(RectangleShape extent, GeographyUnit extentMapUnit, int level, DistanceUnit returnDistanceUnit)
        {
            PointShape centerPoint = extent.GetCenterPoint();

            PointShape centerLeft = new PointShape(extent.LowerLeftPoint.X, centerPoint.Y);
            PointShape centerRight = new PointShape(extent.UpperRightPoint.X, centerPoint.Y);
            PointShape centerUpper = new PointShape(centerPoint.X, extent.UpperLeftPoint.Y);
            PointShape centerLower = new PointShape(centerPoint.X, extent.LowerLeftPoint.Y);

            double centerWidth = centerLeft.GetDistanceTo(centerRight, extentMapUnit, returnDistanceUnit);
            double centerHeight = centerUpper.GetDistanceTo(centerLower, extentMapUnit, returnDistanceUnit);
            double longestEdge = Math.Max(centerWidth, centerHeight);

            double cellWidth = longestEdge / Math.Sqrt(Math.Pow(4, level - 1));
            return cellWidth;
        }
예제 #18
0
        private void DrawInternal(GeoCanvas canvas, Collection <SimpleCandidate> labelsInAllLayers)
        {
            RectangleShape currentBoundingBox = GetBoundingBox();

            AreaStyle brushStyle = BackgroundMask.CloneDeep() as AreaStyle;

            brushStyle.OutlinePen.Width = 0;
            brushStyle.Draw(new BaseShape[] { currentBoundingBox }, canvas, new Collection <SimpleCandidate>(), labelsInAllLayers);

            // Clear Cache images
            if (LastmapExtent != null)
            {
                if (LastmapExtent.UpperLeftPoint.X != MapExtent.UpperLeftPoint.X ||
                    LastmapExtent.UpperLeftPoint.Y != MapExtent.UpperLeftPoint.Y ||
                    LastmapExtent.LowerRightPoint.X != MapExtent.LowerRightPoint.X ||
                    LastmapExtent.LowerRightPoint.Y != MapExtent.LowerRightPoint.Y ||
                    IsDrawing)
                {
                    mapImageCache = null;
                }
            }

            //For adjusting the world extent of the map to the ratio of the drawing area.
            RectangleShape adjustedWorldExtent = ExtentHelper.GetDrawingExtent(MapExtent, (float)currentBoundingBox.Width, (float)currentBoundingBox.Height);
            RectangleShape boundingBox         = GetBoundingBox();
            PointShape     ajustedWorldCenter  = adjustedWorldExtent.GetCenterPoint();
            PageGeoCanvas  pageGeoCanvas       = new PageGeoCanvas(new RectangleShape(0, boundingBox.Height, boundingBox.Width, 0), currentBoundingBox);

            //if (EnableClipping)
            //{
            //    pageGeoCanvas.EnableCliping = true;
            //    pageGeoCanvas.ClipingArea = adjustedWorldExtent;
            //}

            //if (canvas is GdiPlusGeoCanvas && DrawingMode != Core.DrawingMode.Vector)
            // only display on map.
            if (DrawingMode != MapPrinterDrawingMode.Vector && !(canvas is PrinterGeoCanvas))
            {
                double   width  = boundingBox.Width / canvas.CurrentWorldExtent.Width * canvas.Width;
                double   height = boundingBox.Height / canvas.CurrentWorldExtent.Height * canvas.Height;
                GeoImage image  = GetCacheImage(pageGeoCanvas, canvas.MapUnit, adjustedWorldExtent, labelsInAllLayers, width, height);

                pageGeoCanvas.BeginDrawing(canvas, adjustedWorldExtent, MapUnit);
                if (image != null)
                {
                    pageGeoCanvas.DrawWorldImage(image, ajustedWorldCenter.X, ajustedWorldCenter.Y, (float)boundingBox.Width - 0.5f, (float)boundingBox.Height - 0.5f, DrawingLevel.LabelLevel);
                }
                if (DrawDescription)
                {
                    DrawDescriptionText(pageGeoCanvas);
                }
                //pageGeoCanvas.EnableCliping = false;
                pageGeoCanvas.EndDrawing();
            }
            // display on map or printer.
            else
            {
                pageGeoCanvas.BeginDrawing(canvas, adjustedWorldExtent, MapUnit);
                double increase = 0;
                if (BackgroundMask.OutlinePen != null)
                {
                    float haflPenWidth = BackgroundMask.OutlinePen.Width / 2;
                    increase = haflPenWidth * canvas.CurrentWorldExtent.Width / canvas.Width;
                }
                canvas.ClippingArea = new RectangleShape(
                    currentBoundingBox.UpperLeftPoint.X - increase,
                    currentBoundingBox.UpperLeftPoint.Y + increase,
                    currentBoundingBox.LowerRightPoint.X + increase,
                    currentBoundingBox.LowerRightPoint.Y - increase);
                if (canvas is PrinterGeoCanvas)
                {
                    foreach (Layer layer in Layers)
                    {
                        pageGeoCanvas.Flush();

                        float        savedDrawingMarginPercentage = 0;
                        FeatureLayer featureLayer = layer as FeatureLayer;
                        if (featureLayer != null)
                        {
                            savedDrawingMarginPercentage      = featureLayer.DrawingMarginInPixel;
                            featureLayer.DrawingMarginInPixel = 0;
                        }
                        layer.SafeProcess(() =>
                        {
                            layer.Draw(pageGeoCanvas, labelsInAllLayers);
                        });
                        if (featureLayer != null && savedDrawingMarginPercentage != 0)
                        {
                            featureLayer.DrawingMarginInPixel = savedDrawingMarginPercentage;
                        }
                    }
                }
                else
                {
                    using (MemoryStream ms = GetImageStream(canvas, labelsInAllLayers, adjustedWorldExtent, boundingBox))
                    {
                        pageGeoCanvas.DrawWorldImage(new GeoImage(ms), ajustedWorldCenter.X, ajustedWorldCenter.Y, (float)boundingBox.Width - 0.5f, (float)boundingBox.Height - 0.5f, DrawingLevel.LabelLevel);
                    }
                    //foreach (Layer layer in Layers)
                    //{
                    //    pageGeoCanvas.Flush();
                    //    layer.SafeProcess(() =>
                    //    {
                    //        layer.Draw(pageGeoCanvas, labelsInAllLayers);
                    //    });
                    //}
                }
                if (DrawDescription)
                {
                    DrawDescriptionText(pageGeoCanvas);
                }
                //pageGeoCanvas.EnableCliping = false;
                var areaStyle = new AreaStyle(BackgroundMask.OutlinePen)
                {
                    DrawingLevel = DrawingLevel.LabelLevel
                };
                areaStyle.Draw(new BaseShape[1] {
                    currentBoundingBox
                }, canvas, new Collection <SimpleCandidate>(), labelsInAllLayers);
                canvas.ClippingArea = null;
            }

            AreaStyle lineStyle = new AreaStyle(BackgroundMask.OutlinePen.CloneDeep());

            lineStyle.DrawingLevel = DrawingLevel.LabelLevel;
            lineStyle.Draw(new BaseShape[] { currentBoundingBox }, canvas, new Collection <SimpleCandidate>(), labelsInAllLayers);
            LastmapExtent = new RectangleShape(MapExtent.UpperLeftPoint.X, MapExtent.UpperLeftPoint.Y, MapExtent.LowerRightPoint.X, MapExtent.LowerRightPoint.Y);
        }
        private void InitGridDefinition()
        {
            var entity = content.DataContext as GridWizardShareObject;

            RectangleShape gridExtent = new RectangleShape();
            List <Feature> features   = new List <Feature>();

            entity.SelectedFeatureLayer.SafeProcess(() =>
            {
                if (entity.HasSelectedFeatures && entity.OnlyUseSelectedFeatures)
                {
                    features   = GisEditor.SelectionManager.GetSelectedFeatures().Where(f => f.Tag != null && f.Tag == entity.SelectedFeatureLayer).ToList();
                    gridExtent = ExtentHelper.GetBoundingBoxOfItems(features);
                    gridExtent.ScaleUp(0.05);
                }
                else
                {
                    features   = entity.SelectedFeatureLayer.FeatureSource.GetAllFeatures(entity.SelectedFeatureLayer.FeatureSource.GetDistinctColumnNames()).ToList();
                    gridExtent = ExtentHelper.GetBoundingBoxOfItems(features);
                }
            });

            Dictionary <PointShape, double> dataPoints = new Dictionary <PointShape, double>();

            foreach (var item in features)
            {
                double columnValue = double.NaN;
                if (double.TryParse(item.ColumnValues[entity.SelectedDataColumn.ColumnName], out columnValue))
                {
                    var shape = item.GetShape();
                    if (shape.GetType().Equals(typeof(MultipointShape)))
                    {
                        foreach (var point in ((MultipointShape)shape).Points)
                        {
                            point.Tag = null;
                            dataPoints.Add(point, columnValue);
                        }
                    }
                    else
                    {
                        PointShape pointShape = (PointShape)shape;
                        pointShape.Tag = null;
                        dataPoints.Add(pointShape, columnValue);
                    }
                }
            }

            double tmpCellSize = 0.0;

            switch (GisEditor.ActiveMap.MapUnit)
            {
            case GeographyUnit.DecimalDegree:
                tmpCellSize = DecimalDegreesHelper.GetLongitudeDifferenceFromDistance(entity.CellSize, entity.SelectedCellSizeDistanceUnit, gridExtent.GetCenterPoint().Y);
                break;

            case GeographyUnit.Feet:
                tmpCellSize = Conversion.ConvertMeasureUnits(entity.CellSize, entity.SelectedCellSizeDistanceUnit, DistanceUnit.Feet);
                break;

            case GeographyUnit.Meter:
                tmpCellSize = Conversion.ConvertMeasureUnits(entity.CellSize, entity.SelectedCellSizeDistanceUnit, DistanceUnit.Meter);
                break;

            default:
                break;
            }

            entity.GridDefinition = new GridDefinition(gridExtent, tmpCellSize, -9999, dataPoints);
        }
예제 #20
0
        private async static Task Process(ShapeFileFeatureLayer shapeFile, string targetMbtiles, CancellationToken cancellationToken, int minZoom, int maxZoom, int tileSize, List <string> includedAttributes = null)
        {
            Console.Out.WriteLine("Processing tiles. StartZoom:{0}, EndZoom:{1}", minZoom, maxZoom);

            RectangleShape shapeFileBounds = shapeFile.GetBoundingBox();

            shapeFile.Close();

            ThinkGeoMBTilesLayer.CreateDatabase(targetMbtiles);
            var targetDBConnection = new SqliteConnection($"Data Source={targetMbtiles}");

            targetDBConnection.Open();

            // Meta Table
            var targetMetadata = new MetadataTable(targetDBConnection);

            PointShape centerPoint = shapeFileBounds.GetCenterPoint();
            string     center      = $"{centerPoint.X},{centerPoint.Y},{maxZoom}";
            string     bounds      = $"{shapeFileBounds.UpperLeftPoint.X},{shapeFileBounds.UpperLeftPoint.Y},{shapeFileBounds.LowerRightPoint.X},{shapeFileBounds.LowerRightPoint.Y}";

            List <MetadataEntry> Entries = new List <MetadataEntry>();

            Entries.Add(new MetadataEntry()
            {
                Name = "name", Value = "ThinkGeo World Streets"
            });
            Entries.Add(new MetadataEntry()
            {
                Name = "format", Value = "pbf"
            });
            Entries.Add(new MetadataEntry()
            {
                Name = "bounds", Value = bounds
            });                                                                   //"-96.85310250357627,33.10809235525063,-96.85260897712004,33.107616047247156"
            Entries.Add(new MetadataEntry()
            {
                Name = "center", Value = center
            });                                                                   // "-96.85285574034816,33.1078542012489,14"
            Entries.Add(new MetadataEntry()
            {
                Name = "minzoom", Value = $"{minZoom}"
            });
            Entries.Add(new MetadataEntry()
            {
                Name = "maxzoom", Value = $"{maxZoom}"
            });
            Entries.Add(new MetadataEntry()
            {
                Name = "attribution", Value = "Copyright @2020 ThinkGeo LLC.All rights reserved."
            });
            Entries.Add(new MetadataEntry()
            {
                Name = "description", Value = "ThinkGeo World Street Vector Tile Data in EPSG:3857"
            });
            Entries.Add(new MetadataEntry()
            {
                Name = "version", Value = "2.0"
            });
            Entries.Add(new MetadataEntry()
            {
                Name = "json", Value = ""
            });
            targetMetadata.Insert(Entries);

            // Tile Table
            var targetMap             = new TilesTable(targetDBConnection);
            List <TilesEntry> entries = new List <TilesEntry>();

            string targetFolder = Path.Combine(Path.GetDirectoryName(targetMbtiles), Path.GetFileNameWithoutExtension(targetMbtiles), "-tmp");

            if (!Directory.Exists(targetFolder))
            {
                Directory.CreateDirectory(targetFolder);
            }

            SphericalMercatorZoomLevelSet zoomLevelSet = new SphericalMercatorZoomLevelSet();
            double      currentScale = GetZoomLevelIndex(zoomLevelSet, minZoom);
            var         tileMatrix   = TileMatrix.GetDefaultMatrix(currentScale, tileSize, tileSize, GeographyUnit.Meter);
            var         tileRange    = tileMatrix.GetIntersectingRowColumnRange(shapeFileBounds);
            List <Task> tasks        = new List <Task>();

            for (long tileY = tileRange.MinRowIndex; tileY <= tileRange.MaxRowIndex && !cancellationToken.IsCancellationRequested; ++tileY)
            {
                for (long tileX = tileRange.MinColumnIndex; tileX <= tileRange.MaxColumnIndex && !cancellationToken.IsCancellationRequested; ++tileX)
                {
                    Task task = ProcessTileRecursive(shapeFile, (int)tileY, (int)tileX, minZoom, maxZoom, cancellationToken, targetFolder, includedAttributes);
                    tasks.Add(task);
                }
            }

            foreach (var task in tasks)
            {
                await task;
            }

            await Task.Run(() =>
            {
                long index = 0;

                string[] files = Directory.GetFiles(targetFolder, "*.mvt");
                foreach (string file in files)
                {
                    string fileName     = Path.GetFileNameWithoutExtension(file);
                    string[] NameValues = fileName.Split('_');

                    byte[] bytes = File.ReadAllBytes(file);

                    TilesEntry newEntry = new TilesEntry();
                    int zoomLevel       = int.Parse(NameValues[0]);
                    newEntry.ZoomLevel  = zoomLevel;
                    long row            = long.Parse(NameValues[1]);
                    row = (long)Math.Pow(2, zoomLevel) - row - 1;
                    newEntry.TileRow    = row;
                    newEntry.TileColumn = long.Parse(NameValues[2]);
                    newEntry.TileId     = index++;
                    newEntry.TileData   = bytes;
                    File.Delete(file);

                    entries.Add(newEntry);

                    if (index % 1000 == 0)
                    {
                        targetMap.Insert(entries);
                        entries.Clear();
                        continue;
                    }
                }
                targetMap.Insert(entries);
            });

            targetDBConnection.Close();
        }