Exemplo n.º 1
0
 private void mapControl_BeforeMapRender(object sender, MapAround.UI.WinForms.ViewBoxEventArgs e)
 {
     _map.LoadRasters(mapControl.ClientSize.Height / e.ViewBox.Height, e.ViewBox); //Loading raster layer for this viewbox
 }
Exemplo n.º 2
0
        void mapControl_SelectionRectangleDefined(object sender, MapAround.UI.WinForms.ViewBoxEventArgs e)
        {
            // create a list instance for selected features 
            List<Feature> selectedFeatures = new List<Feature>();

            // translate view box to map data coordinates 
            BoundingRectangle br = mapControl.Map.MapViewBoxFromPresentationViewBox(e.ViewBox);
            FeatureLayer l = (FeatureLayer)mapControl.Map.Layers[0];

            // and do primary filter 
            l.SelectObjects(br, selectedFeatures);

            // turn off selection 
            foreach (Feature f in l.Features)
            {
                f.Selected = false;
            }

            Polygon p = null;

            // if the map has on-the-fly transformation, convert initial view box  
            // to polygon and transform its coordinates to map data coordinates 
            if (mapControl.Map.OnTheFlyTransform != null)
            {
                p = e.ViewBox.ToPolygon();
                IMathTransform inverseTransform = mapControl.Map.OnTheFlyTransform.Inverse();
                p = GeometryTransformer.TransformPolygon(p, inverseTransform);
            }

            foreach (Feature f in selectedFeatures)
            {
                if (mapControl.Map.OnTheFlyTransform != null)
                {
                    // do more expensive secondary filter 
                    if (p.Intersects((ISpatialRelative)f.Geometry))
                    {
                        f.Selected = true;
                    }
                }
                else
                {
                    // if our map hasn't on-the-fly transformation, primary filter is fine, 
                    // so, set selection state 
                    f.Selected = true;
                }
            }

         
            mapControl.RedrawMap(); 
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retreives a chunk of the raster.
        /// </summary>
        /// <param name="srcX">A minimum X coordinate of the querying area</param>
        /// <param name="srcY">A minimum Y coordinate of the querying area</param>
        /// <param name="srcWidth">A width of the querying area</param>
        /// <param name="srcHeight">A height of the querying area</param>
        /// <param name="maxDestWidth">A maximum width in pixels of the resulting raster</param>
        /// <param name="maxDestHeight">A maximum height in pixels of the resulting raster</param>
        /// <param name="bounds">A bounds of querying area on the map</param>
        /// <param name="receiver">An object receiving raster</param>
        public void QueryRaster(int srcX, int srcY, int srcWidth, int srcHeight, int maxDestWidth, int maxDestHeight, MapAround.Geometry.BoundingRectangle bounds, MapAround.Mapping.IRasterReceiver receiver)
        {
            if (srcX < 0)
                throw new ArgumentException("Minimum X of the querying area should not be negative", "srcX");

            if (srcY < 0)
                throw new ArgumentException("Minimum Y of the querying area should not be negative", "srcY");

            if (srcWidth <= 0)
                throw new ArgumentException("A width of the querying area should be positive", "srcWidth");

            if (srcHeight <= 0)
                throw new ArgumentException("A height of the querying area should be positive", "srcHeight");

            Bitmap bitmap = null;
            BitmapData bitmapData = null;
            double[] intVal = new double[_bandCount];
            int pIndex;
            double bitScalar = 1.0;

            // scale
            if (_bitDepth == 12)
                bitScalar = 16.0;
            else if (_bitDepth == 16)
                bitScalar = 256.0;
            else if (_bitDepth == 32)
                bitScalar = 16777216.0;

            int iPixelSize = 3;

            try
            {
                bitmap = new Bitmap(Math.Max(maxDestWidth, 1), Math.Max(maxDestHeight, 1), PixelFormat.Format24bppRgb);
                bitmapData =
                    bitmap.LockBits(
                        new Rectangle(0, 0, Math.Max(maxDestWidth, 1), Math.Max(maxDestHeight, 1)), ImageLockMode.ReadWrite, bitmap.PixelFormat);

                unsafe
                {
                    double[][] buffer = new double[_bandCount][];
                    Band[] band = new Band[_bandCount];
                    int[] ch = new int[_bandCount];

                    // get data from image
                    for (int i = 0; i < _bandCount; i++)
                    {
                        buffer[i] = new double[maxDestWidth * maxDestHeight];
                        band[i] = _gdalDataset.GetRasterBand(i + 1);

                        band[i].ReadRaster(
                            srcX,          // xOff
                            srcY,          // yOff
                            srcWidth,      // xSize
                            srcHeight,     // ySize
                            buffer[i],     // buffer 
                            maxDestWidth,  // buf_xSize 
                            maxDestHeight, // buf_ySize
                            0,             // pixelSpace
                            0);            // lineSpace

                        if (band[i].GetRasterColorInterpretation() == ColorInterp.GCI_BlueBand) ch[i] = 0;
                        else if (band[i].GetRasterColorInterpretation() == ColorInterp.GCI_GreenBand) ch[i] = 1;
                        else if (band[i].GetRasterColorInterpretation() == ColorInterp.GCI_RedBand) ch[i] = 2;
                        else if (band[i].GetRasterColorInterpretation() == ColorInterp.GCI_Undefined)
                            ch[i] = 3; // infrared
                        else if (band[i].GetRasterColorInterpretation() == ColorInterp.GCI_GrayIndex) ch[i] = 4;
                        else ch[i] = -1;
                    }

                    if (_bitDepth == 32)
                        ch = new int[] { 0, 1, 2 };

                    pIndex = 0;
                    for (int y = 0; y < maxDestHeight; y++)
                    {
                        byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride);
                        for (int x = 0; x < maxDestWidth; x++, pIndex++)
                        {
                            for (int i = 0; i < _bandCount; i++)
                            {
                                intVal[i] = buffer[i][pIndex] / bitScalar;

                                if (intVal[i] > 255)
                                    intVal[i] = 255;
                            }

                            writePixel(x, intVal, iPixelSize, ch, row);
                        }
                    }
                }
            }
            finally
            {
                if (bitmapData != null)
                    bitmap.UnlockBits(bitmapData);
            }

            receiver.AddRasterPreview(bitmap, bounds, Width, Height);
        }
Exemplo n.º 4
0
        private void LayerDataSourceReadyToRelease(object sender, MapAround.Mapping.FeatureDataSourceEventArgs e)
        {
            FeatureLayer l = sender as FeatureLayer;

            switch (l.DataProviderRegName)
            {
               

                case "MapAround.DataProviders.ShapeFileSpatialDataProvider":
                    break;

               

                default:
                    throw new Exception("Map data provider not found: \"" + l.DataProviderRegName + "\"");
            }
        }
Exemplo n.º 5
0
        private void LayerDataSourceNeeded(object sender, MapAround.Mapping.FeatureDataSourceEventArgs e)
        {
            FeatureLayer l = sender as FeatureLayer;
            string featuresFilePath = string.Empty;
            switch (l.DataProviderRegName)
            {
              

                case "MapAround.DataProviders.ShapeFileSpatialDataProvider":
                    l.AreFeaturesAutoLoadable = true;
                    ShapeFileSpatialDataProvider shapeP = new ShapeFileSpatialDataProvider();
                    shapeP.AttributesEncoding = Encoding.UTF8;
                    shapeP.FileName = GetFeaturesFilePath(l.DataProviderParameters["file_name"]);
                    shapeP.ProcessAttributes = true;                    
                    e.Provider = shapeP;
                    break;
                default:
                    throw new Exception("Map data provider not found: \"" + l.DataProviderRegName + "\"");
            }
        }
Exemplo n.º 6
0
        private void buildAndSaveIndex(MapAround.Mapping.FeatureType featureType, 
                               BoundingRectangle b,
                               IndexSettings settings, 
                               IEnumerable<Feature> features)
        {
            ISpatialIndex index = null;

            if (b.IsEmpty())
                b = new BoundingRectangle(0, 0, 0, 0);

            if (settings.IndexType == "QuadTree")
                index = new QuadTree(b);
            if (index == null)
                index = new KDTree(b);

            index.MaxDepth = settings.MaxDepth;
            index.BoxSquareThreshold = settings.BoxSquareThreshold;
            index.MinObjectCount = settings.MinFeatureCount;

            index.Build(features);

            _cacheAccessor.SaveFeaturesIndex(index, featureType);
        }