コード例 #1
0
        public static Geometry ConvertPointsToBoundingBox(List <LatLon> boundingBoxPoints)
        {
            var factory  = new NetTopologySuite.Geometries.OgcCompliantGeometryFactory(); //helps make polygon shell counter clockwise
            var polyLine = factory.CreateLineString(boundingBoxPoints.Select(p => new NetTopologySuite.Geometries.Coordinate((double)p.Longitude, (double)p.Latitude)).ToArray());

            return(polyLine.Envelope);
        }
コード例 #2
0
ファイル: QuadTree.cs プロジェクト: hakbra/SGIS
        // creates new node with given boundary
        public QuadTree(double minx, double maxx, double miny, double maxy)
        {
            boundary = new Envelope(minx, maxx, miny, maxy);

            OgcCompliantGeometryFactory fact = new OgcCompliantGeometryFactory();
            gboundary = fact.ToGeometry(boundary);
        }
コード例 #3
0
ファイル: Photo.cs プロジェクト: hakbra/SGIS
        public Photo(System.Drawing.Image i, ScreenManager.SGISEnvelope b)
        {
            Pic = i;
            Bounds = new ScreenManager.SGISEnvelope(b);

            OgcCompliantGeometryFactory fact = new OgcCompliantGeometryFactory();
            Geometry = fact.ToGeometry(b);
        }
コード例 #4
0
ファイル: ScreenManager.cs プロジェクト: hakbra/SGIS
        public IGeometry MapScreenToRealGeometry(Envelope e)
        {
            var min = MapScreenToReal(new System.Drawing.Point((int)e.MinX, (int)e.MinY));
            var max = MapScreenToReal(new System.Drawing.Point((int)e.MaxX, (int)e.MaxY));
            var re = new Envelope(min.X, max.X, min.Y, max.Y);

            OgcCompliantGeometryFactory fact = new OgcCompliantGeometryFactory();
            return fact.ToGeometry(re);
        }
コード例 #5
0
ファイル: SGIS_Tools.cs プロジェクト: hakbra/SGIS
        // export map as raster-image
        private void renderButton_Click(object sender, EventArgs e)
        {
            toolBuilder.addHeader("Export to GeoTiff", false);
            // textbox for increase in resolution
            var zoom = toolBuilder.addTextboxWithCaption("Zoom factor:", "1");
            // textbox and button for new file name input
            var file = toolBuilder.addTextboxWithCaption("Filename:", "");
            var browsebutton = toolBuilder.addButton("Browse...");
            browsebutton.Click += (o, w) =>
            {
                 SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                 saveFileDialog1.Filter = "bmp files (*.bmp)|*.bmp"  ;
                 if(saveFileDialog1.ShowDialog() == DialogResult.OK)
                     file.Text = saveFileDialog1.FileName;
            };
            // label for errors
            var error = toolBuilder.addErrorLabel();

            // button for performing rasterization
            Button button = toolBuilder.addButton("Export", (Layer selectedLayer) =>
            {
                // no filename is given
                if (file.Text == "")
                {
                    toolBuilder.setError("Please provide filename");
                    return;
                }
                // æøå not accepted in filename, not supported by GDAL
                if (file.Text.ToLower().IndexOfAny("æøå".ToCharArray()) > -1)
                {
                    toolBuilder.setError("No æøå in filename");
                    return;
                }
                double zoomfactor = 1;
                if (!double.TryParse(zoom.Text, out zoomfactor))
                {
                    // zoom factor must be a number
                    toolBuilder.setError("Zoom factor not a number");
                    return;
                }

                // calulate image resolution and new real world coordinates
                var oldWindowRect = ScreenManager.WindowsRect.Clone();
                ScreenManager.WindowsRect = new ScreenManager.SGISEnvelope(0, oldWindowRect.MaxX * zoomfactor, 0, oldWindowRect.MaxY * zoomfactor);
                ScreenManager.Calculate();
                Bitmap mapTemp = new Bitmap((int)ScreenManager.WindowsRect.Width,
                                            (int)ScreenManager.WindowsRect.Height);
                var mapRectTemp = ScreenManager.MapScreenToReal(ScreenManager.WindowsRect);
                OgcCompliantGeometryFactory fact = new OgcCompliantGeometryFactory();
                var boundingGeometry = fact.ToGeometry(mapRectTemp);
                Render render = new Render(ScreenManager.Scale, ScreenManager.Offset);
                ScreenManager.WindowsRect.Set(oldWindowRect);
                ScreenManager.Calculate();

                // background worker for performing rasterisation in another thread
                BackgroundWorker bwRender = new BackgroundWorker();
                bwRender.DoWork += (obj, args) =>
                {
                    var mapGraphics = Graphics.FromImage(mapTemp);

                    // draw background maps
                    foreach (Photo p in photos)
                    {
                        // only if visible
                        if (p.Geometry.Intersects(boundingGeometry))
                            render.Draw(p, mapGraphics);
                    }
                    // draw layers
                    foreach (Layer l in Layers.Reverse())
                    {
                        // only if visible
                        if (!l.Visible)
                            continue;
                        // draw only visible features
                        var visibleFeatures = l.getWithin(boundingGeometry);
                        lock (l) // lock layer to prevent multithreaded access to style when drawing
                        {
                            // render feature
                            foreach (Feature s in visibleFeatures)
                            {
                                render.Draw(s.Geometry, mapGraphics, l.Style);
                            }
                        }
                    }
                };
                // georeference drawn bitmap
                bwRender.RunWorkerCompleted += (obj, args) =>
                {
                    // remove .bmp ending if present
                    if (file.Text.EndsWith(".bmp"))
                        file.Text = file.Text.Substring(0, file.Text.Length-4);
                    // save render
                    mapTemp.Save(file.Text+".bmp");

                   // init GDAL and copy image
                   OSGeo.GDAL.Gdal.AllRegister();
                   OSGeo.GDAL.Driver srcDrv = OSGeo.GDAL.Gdal.GetDriverByName("GTiff");
                   OSGeo.GDAL.Dataset srcDs = OSGeo.GDAL.Gdal.Open(file.Text+".bmp", OSGeo.GDAL.Access.GA_ReadOnly);
                   OSGeo.GDAL.Dataset dstDs = srcDrv.CreateCopy(file.Text+".tiff", srcDs, 0, null, null, null);

                   //Set the map projection
                    {
                        OSGeo.OSR.SpatialReference oSRS = new OSGeo.OSR.SpatialReference("");
                        oSRS.ImportFromProj4( SRS.ToString() );
                        string wkt;
                        // convert projection to wkt
                        oSRS.ExportToWkt(out wkt);
                        dstDs.SetProjection(wkt);
                   }

                   //Set the map coordinates
                   double mapWidth = mapRectTemp.Width;
                   double mapHeight = mapRectTemp.Height;
                   double[] geoTransfo = new double[] { mapRectTemp.MinX, mapWidth / mapTemp.Width, 0, mapRectTemp.MaxY, 0, -mapHeight / mapTemp.Height };
                   dstDs.SetGeoTransform(geoTransfo);

                   dstDs.FlushCache();
                   dstDs.Dispose();
                   srcDs.Dispose();
                   srcDrv.Dispose();

                    /////////////////////////
                };
                bwRender.RunWorkerAsync();
            });
        }
コード例 #6
0
ファイル: SGIS.cs プロジェクト: hakbra/SGIS
        // draws map
        private void SGIS_Paint(object sender, PaintEventArgs e)
        {
            // if map is to be cmpletely redrawn
            if (mapDirty)
            {
                mapDirty = false;
                // create temporary map and bounding box
                Bitmap mapTemp = new Bitmap(mapWindow.Width, mapWindow.Height);
                var mapRectTemp = ScreenManager.MapScreenToReal(ScreenManager.WindowsRect);
                Layer selectedLayer = (Layer)layerList.SelectedItem;
                OgcCompliantGeometryFactory fact = new OgcCompliantGeometryFactory();
                var boundingGeometry = fact.ToGeometry(mapRectTemp);
                // create new render instance
                Render render = new Render(ScreenManager.Scale, ScreenManager.Offset);

                // if we are already rendering a new map
                if (bw.IsBusy)
                {
                    // cancel previous rendering
                    bw.CancelAsync();
                    while(bw.IsBusy)
                        Application.DoEvents();
                }
                bw = new BackgroundWorker();
                bw.WorkerSupportsCancellation = true;
                // start new rendering in other thread
                // this avoids making the application unresponsive
                bw.DoWork += (obj, args) =>
                {
                    var mapGraphics = Graphics.FromImage(mapTemp);

                    // draw wms-maps
                    foreach(Photo p in photos)
                    {
                        if (p.Geometry.Intersects(boundingGeometry))
                            p.Draw(mapGraphics);
                    }

                    // draw layers
                    foreach (Layer l in Layers.Reverse())
                    {
                        // skip layer if not visible
                        if (!l.Visible)
                            continue;
                        // get all visible features in layer
                        var visibleFeatures = l.getWithin(boundingGeometry);
                        lock (l)
                        {
                            // draw feature
                            foreach (Feature s in visibleFeatures)
                            {
                                // abort if this rendering has been cancelled
                                if (bw.CancellationPending)
                                {
                                    args.Cancel = true;
                                    return;
                                }
                                if (!s.Selected || l != selectedLayer)
                                    render.Draw(s.Geometry, mapGraphics, l.Style);
                                else if (l == selectedLayer)
                                    render.Draw(s.Geometry, mapGraphics, Style.Selected);
                            }
                            // render quad tree, only for debug purposes
                            //if (l.QuadTree != null)
                            //    l.QuadTree.render(e.Graphics);
                        }
                    }
                };
                bw.RunWorkerCompleted += (obj, args) =>
                {
                    // if rendering was not cancelled
                    if (!args.Cancelled)
                    {
                        // copy temporary map to stored map
                        map = mapTemp;
                        mapRect = mapRectTemp;
                        // draw new map
                        redrawDirty();
                    }
                };
                bw.RunWorkerAsync();
            }

            try
            {
                // draw map stored in member map
                var screenRect = ScreenManager.MapRealToScreen(mapRect);

                // draw background color
                if (mapBgColor != Color.White)
                    e.Graphics.Clear(mapBgColor);

                e.Graphics.DrawImage(map, screenRect);
            }
            catch (Exception ex)
            {
                // Will happen after changing SRS
            }

            // if current srs is projected, draw scale in lower left corner
            if (!SRS.IsLatLong)
                renderScale(e.Graphics);

            // calls mouse render function, will only draw select-rectangle when select is being used
            mouse.render(e.Graphics);
        }