Ejemplo n.º 1
0
 private IRasterLayer IntersectRaster(IRasterLayer rsterLayer, IPolygon polygon2)
 {
     //  获得与组合成的面相叠加的栅格
     if (radioBtnKJ.Checked && polygon2 != null)
     {
         IExtractionOp op = new RasterExtractionOpClass();
         IGeoDataset dataset = op.Polygon((IGeoDataset)rsterLayer.Raster, polygon2, true);
         IRasterLayer layer = new RasterLayerClass();
         layer.CreateFromRaster((IRaster)dataset);
         rsterLayer = layer;
     }
     return rsterLayer;
 }
Ejemplo n.º 2
0
        private KeyValuePair<IGeoDataset, IGeoDataset> computeWatershed(IPoint pour_point, IEnvelope analysisExtent)
        {
            try
            {
                //bodge the input point into its nasty shell of arcobjects junk for analysis
                IHydrologyOp pHydrologyOp = new RasterHydrologyOp() as IHydrologyOp;
                IPointCollection3 tPointCollection = new MultipointClass();
                object tPointlessMissingObject = Type.Missing;
                tPointCollection.AddPoint(pour_point, ref tPointlessMissingObject, ref tPointlessMissingObject);

                // open the accumulation and direction datasets, hardcoded
                //IGeoDataset tAccum = OpenRasterDataset(data_path, accum_name) as IGeoDataset;
                //IGeoDataset tDirection = OpenRasterDataset(data_path, dir_name) as IGeoDataset;
                //bodge the input extent into its nasty shell of arcobjects junk
                IRasterAnalysisEnvironment tRasterAnalysisEnvironment = new RasterAnalysisClass();
                if (analysisExtent != null)
                {
                    IRelationalOperator tCheckRequestedExtent = analysisExtent as IRelationalOperator;
                    if (tCheckRequestedExtent != null && tCheckRequestedExtent.Contains(pour_point))
                    {
                        // can anyone explain why these things have to be objects? Why can't there be interfaces
                        // for AnalysisExtentProvider and SnapObject that the datasets implement?
                        object tAnalysisEnvelopePointlesslyCastedToObject = (System.Object)analysisExtent;
                        object tAnotherPointlessMissingObject = Type.Missing;
                        //object tSnapObject = (System.Object)tDirection;
                        object tSnapObject = (System.Object)m_FlowDirDataset;
                        tRasterAnalysisEnvironment.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue,
                            ref tAnalysisEnvelopePointlesslyCastedToObject, ref tSnapObject);
                        tRasterAnalysisEnvironment.SetAsNewDefaultEnvironment();
                    }
                    else
                    {
                        logger.LogMessage(ServerLogger.msgType.warning, "create watershed", 8000,
                            "Input point was not within requested analysis extent. Analysis extent will be ignored (may be slow)!");
                    }
                }
                else
                {
                    logger.LogMessage(ServerLogger.msgType.warning, "create watershed", 8000,
                        "No analysis extent requested. Full extent will be used (may be slow)!");

                }
                IExtractionOp tExtractionOp = new RasterExtractionOpClass();

                // Do the work: snap the point to a snapped-pour-point grid and use it to calcualte the watershed
                //IGeoDataset tPourPointGrid = tExtractionOp.Points(tDirection, tPointCollection, true);
                IGeoDataset tPourPointGrid = tExtractionOp.Points(m_FlowDirDataset, tPointCollection, true);
                //IGeoDataset snapRaster = pHydrologyOp.SnapPourPoint(tPourPointGrid, tAccum, 100);
                IGeoDataset snapRaster = pHydrologyOp.SnapPourPoint(tPourPointGrid, m_FlowAccDataset, 100);
                // check the snapping worked..?
                // calculate the watershed!
                //IGeoDataset watershedRaster = pHydrologyOp.Watershed(tDirection, snapRaster);
                IGeoDataset watershedRaster = pHydrologyOp.Watershed(m_FlowDirDataset, snapRaster);
                //  restore previous default analysis extent if we changed it (should = whole dataset)
                if (analysisExtent != null)
                {
                    tRasterAnalysisEnvironment.RestoreToPreviousDefaultEnvironment();
                }
                // change it to a polygon feature (will have the area added) and return it
                IGeoDataset tWatershedPolygonGDS = ConvertAndUnionWatershed(watershedRaster);
                KeyValuePair<IGeoDataset, IGeoDataset> tRasterPolyPair = new KeyValuePair<IGeoDataset, IGeoDataset>(watershedRaster, tWatershedPolygonGDS);
                return tRasterPolyPair;
            }
            catch (Exception e)
            {
                logger.LogMessage(ServerLogger.msgType.infoStandard, "Compute watershed error: ", 8000, e.Message);
                logger.LogMessage(ServerLogger.msgType.infoStandard, "Compute watershed error: ", 8000, e.ToString());
                logger.LogMessage(ServerLogger.msgType.infoStandard, "Compute watershed error: ", 8000, e.TargetSite.Name);
                logger.LogMessage(ServerLogger.msgType.infoStandard, "Compute watershed error: ", 8000, e.StackTrace);
            }
            return new KeyValuePair<IGeoDataset, IGeoDataset>();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="_pGdsLocation"></param>
 /// <param name="_BandCol"></param>
 /// <returns></returns>
 private ITable ExportSample(IGeoDataset _pGdsLocation, IRasterBandCollection _BandCol)
 {
     //IRasterLayer pRastetLayer = pLayer as IRasterLayer;
     //IRasterBandCollection pRasterBandColection = pRastetLayer.Raster as IRasterBandCollection;
     //if (pRasterBandColection.Count == 1)
     //{
         //Create the RasterExtractionOp object
         IExtractionOp pExtractionOp = new RasterExtractionOpClass();
         ////Declare the input location raster object
         //IGeoDataset pGdsLocation=_pGdsLocation;
         ////Create a raster of multiple bands
         //IRasterBandCollection pBandCol=_BandCol;
         ////Declare the output table object
         ITable pOutputTable;
         //Calls the method
         pOutputTable = pExtractionOp.Sample(_pGdsLocation, _BandCol as IGeoDataset, esriGeoAnalysisResampleEnum.esriGeoAnalysisResampleNearest);
         return pOutputTable;
     //}
 }
        internal static RasterExtractionResult SummariseRaster(IGeoDataset pClippingPolygon, ExtractionLayerConfig pExtractionLayerConfig)
        {
            // set the analysis extent to be that of the polygon
            ServerLogger logger = new ServerLogger();
            logger.LogMessage(ServerLogger.msgType.debug, "SummariseCategoricalRaster", 99, "Categorical raster clip beginning..");
            IEnvelope tAnalysisExtent = pClippingPolygon.Extent;

            bool pCategoricalSummary = pExtractionLayerConfig.ExtractionType==ExtractionTypes.CategoricalRaster;
            IGeoDataset pRasterToClip = pExtractionLayerConfig.LayerDataset;

            IRasterAnalysisEnvironment tRasterAnalysisEnvironment = new RasterAnalysisClass();
            object tAnalysisEnvelopeCastToObject = (System.Object)tAnalysisExtent;
               // object tAnotherBizarreMissingObject = Type.Missing;
            object tSnapObject = (System.Object)pRasterToClip;
            tRasterAnalysisEnvironment.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue,
                ref tAnalysisEnvelopeCastToObject, ref tSnapObject);
            tRasterAnalysisEnvironment.SetAsNewDefaultEnvironment();
            // extract the subset of the raster
            IExtractionOp2 tExtractionOp = new RasterExtractionOpClass();
            // note we want to base the extraction on a raster (in an IGeoDataset) rather than an IPolygon.
            // That's because the catchment polygon may be multipart, and the operation doesn't work with multipart.
            // Also the polygon has a max of 1000 vertices.
            // And raster mask extraction is probably faster since the
            // polygon is converted internally to a grid anyway.
            IGeoDataset tClipped;
            if (pRasterToClip as IRaster != null)
            {
                logger.LogMessage(ServerLogger.msgType.debug, "SummariseRaster", 99,
                    "Input was in raster form, using directly to clip...");
                tClipped = tExtractionOp.Raster(pRasterToClip, pClippingPolygon);
            }
            else
            {
                // POLYGON VERSION: tExtractionOp.Polygon(pClipRaster,pPolygon,true)
                // sometimes we need to be able to pass in a polygon but rather than using the polygon
                // method we'll manually convert to a mask raster to avoid the issues above
                // It would save work to do this once for each request rather than repeat the conversion
                // for each layer - but we might want a different environment (snap extent etc) for each.
                logger.LogMessage(ServerLogger.msgType.debug, "SummariseCategoricalRaster", 99,
                    "Converting input polygon to mask raster for clip...");
                IRasterConvertHelper tConvertPolygonToRaster = new RasterConvertHelperClass();
                // convert it to a raster with the same cell size as the input
                IRasterProps tRst = pRasterToClip as IRasterProps;
                IPnt tRstCellSize = tRst.MeanCellSize();
                double x = tRstCellSize.X;
                double y = tRstCellSize.Y;
                double cellSize = Math.Round(Math.Min(x, y), 0);
                object tCellSizeAsObjectForNoGoodReason = (System.Object)cellSize;
                tRasterAnalysisEnvironment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue,
                    ref tCellSizeAsObjectForNoGoodReason);
                IGeoDataset tPolyAsRast =
                    tConvertPolygonToRaster.ToRaster1(pRasterToClip, "GRID", tRasterAnalysisEnvironment)
                as IGeoDataset;
                logger.LogMessage(ServerLogger.msgType.debug, "SummariseCategoricalRaster", 99,
                    "...done, proceeding with clip");
                tClipped = tExtractionOp.Raster(pRasterToClip, tPolyAsRast);
            }
            // now we have the clipped raster we need to summarise it differently depending on whether
            // we want a summary by category/value (for categorical rasters) or by stats (for float rasters)
            Dictionary<string, double> tResults;
            if (pCategoricalSummary)
            {
                tResults = WatershedDetailExtraction.SummariseRasterCategorically(tClipped);
                if (tResults.Count > 100)
                {
                    // sanity check: don't sum up more than 100 different values
                    tResults = WatershedDetailExtraction.SummariseRasterStatistically(tClipped);
                    pCategoricalSummary = false;
                }
            }
            else
            {
                tResults = WatershedDetailExtraction.SummariseRasterStatistically(tClipped);
            }
            tRasterAnalysisEnvironment.RestoreToPreviousDefaultEnvironment();
            return new RasterExtractionResult(pExtractionLayerConfig.ParamName, pCategoricalSummary, tResults);
            //return tResults;
        }
        private void Extract(IRasterLayer pRasterLayer,IFeatureLayer pFeatureLayer)
        {
            try
            {

                IRaster pRaster = pRasterLayer.Raster;
                IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;

                ToggleSA(true);

                IExtractionOp2 pExtractionOp = new RasterExtractionOpClass();

                IGeoDataset pOutGeoDS = pExtractionOp.ExtractValuesToPoints(pFeatureClass as IGeoDataset, pRaster as IGeoDataset, false);

                IFeatureLayer player = new FeatureLayerClass();
                player.FeatureClass = pOutGeoDS as IFeatureClass;
                player.Name = "Raster2Points";

                string g =  System.IO.Path.GetDirectoryName (strSaveFile);
                if (System.IO.File.Exists(strSaveFile))
                {
                    System.IO.File.Delete(strSaveFile);
                }
                ITable ptable = player.FeatureClass as ITable;
                ExportTable2DBF(ptable, System.IO.Path.GetDirectoryName (strSaveFile),System.IO.Path.GetFileName (strSaveFile));
                AddTable(System.IO.Path.GetDirectoryName(strSaveFile), System.IO.Path.GetFileName(strSaveFile));
                ArcMap.Document.ActiveView.FocusMap.AddLayer(player);
                ToggleSA(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
        }
Ejemplo n.º 6
0
       //
		private void buttonApply_Click(object sender, System.EventArgs e)
		{
			try
			{
				IQueryFilter pQueryFilter=new QueryFilterClass();
				AxMapControl axMap=pMainFrm.getMapControl();
				string sLayerName=comboBoxLayer.Text;
				bool bLayerType=GetLayerType(sLayerName);
				IActiveView pActiveView=axMap.Map as IActiveView ;
			                 
				if(bLayerType==false)
				{
					pQueryFilter.WhereClause=textBox1.Text;		 
					IFeatureCursor pFeatCursor=m_pFeatCls.Search(pQueryFilter,false);
					IFeature pFeature=pFeatCursor.NextFeature();
 
					axMap.Map.ClearSelection();
					IEnvelope pEnvelope=new EnvelopeClass();
					ILayer pLayer=GetLayerFromName(sLayerName);
					
					while(pFeature!=null)
					{
						axMap.Map.SelectFeature(pLayer,pFeature);
						pEnvelope.Union(pFeature.Extent.Envelope);
						pFeature=pFeatCursor.NextFeature();
					}		
					axMap.Extent=pEnvelope;
					pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection,null,null);	
					pActiveView.Refresh();
				 
				}
				else
				{
					IRasterDescriptor pRasDes=new RasterDescriptorClass();
					pQueryFilter.WhereClause=textBox1.Text;		
					pRasDes.Create(m_pRaster,pQueryFilter,listBoxField.Text);
					IExtractionOp pExtrOp=new RasterExtractionOpClass();
					IRaster pRaster=pExtrOp.Attribute(pRasDes) as Raster ;
					IRasterLayer pRsLayer=new RasterLayerClass();
					pRsLayer.CreateFromRaster(pRaster);
					axMap.Map.AddLayer(pRsLayer);
					pActiveView.Refresh();
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			
			}

		}