public static ISpatialReference ReadSR(string pPrjFilePath) { if (File.Exists(pPrjFilePath)) { StreamReader aReader = new StreamReader(pPrjFilePath); string aLine = aReader.ReadToEnd(); aReader.Close(); int byteCount = 0; if (aLine.StartsWith("GEOGCS")) { GeographicCoordinateSystemClass sr = new GeographicCoordinateSystemClass(); (sr as IESRISpatialReference).ImportFromESRISpatialReference(aLine, out byteCount); return(sr); } else { ProjectedCoordinateSystemClass sr = new ProjectedCoordinateSystemClass(); (sr as IESRISpatialReference).ImportFromESRISpatialReference(aLine, out byteCount); return(sr); } } else { return(null); } }
public ISpatialReference CreateSpatialReferenceGCS(string sSRString) { try { if (string.IsNullOrEmpty(sSRString)) { return(null); } IESRISpatialReference reference = null; reference = new GeographicCoordinateSystemClass(); int cBytesRead = 0; reference.ImportFromESRISpatialReference(sSRString, out cBytesRead); return(reference as ISpatialReference); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.GeometryFun", "CreateSpatialReferenceGCS", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(null); } }
private void CreateGeographicCoordinateSystem() { ISpatialReferenceFactory3 spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); IDatum datum = spatialReferenceFactory.CreateDatum((int)esriSRDatumType.esriSRDatum_OSGB1936); IPrimeMeridian primeMeridian = spatialReferenceFactory.CreatePrimeMeridian((int)esriSRPrimeMType.esriSRPrimeM_Greenwich); IUnit unit = spatialReferenceFactory.CreateUnit((int)esriSRUnitType.esriSRUnit_Degree); IGeographicCoordinateSystemEdit geographicCoordinateSystemEdit = new GeographicCoordinateSystemClass(); object name = "UserDefined Geographic Coordinate System"; object alias = "UserDefined GCS"; object abbreviation = "UserDefined"; object remarks = "User Defined Geographic Coordinate System based on OSGB1936"; object usage = "Suitable for the UK"; object datumObject = datum as object; object primeMeridianObject = primeMeridian as object; object unitObject = unit as object; geographicCoordinateSystemEdit.Define(ref name, ref alias, ref abbreviation, ref remarks, ref usage, ref datumObject, ref primeMeridianObject, ref unitObject); IGeographicCoordinateSystem userDefinedGeographicCoordinateSystem = geographicCoordinateSystemEdit as IGeographicCoordinateSystem; m_map.SpatialReference = userDefinedGeographicCoordinateSystem; m_activeView.Refresh(); MessageBox.Show("已将当前坐标系统转换为自定义GeographicCoordinateSystem!"); }
public static ISpatialReference ReadSR(string pPrjFilePath) { if (File.Exists(pPrjFilePath)) { StreamReader aReader = new StreamReader(pPrjFilePath); string aLine = aReader.ReadToEnd(); aReader.Close(); int byteCount = 0; if (aLine.StartsWith("GEOGCS")) { GeographicCoordinateSystemClass sr = new GeographicCoordinateSystemClass(); (sr as IESRISpatialReference).ImportFromESRISpatialReference(aLine, out byteCount); return sr; } else { ProjectedCoordinateSystemClass sr = new ProjectedCoordinateSystemClass(); (sr as IESRISpatialReference).ImportFromESRISpatialReference(aLine, out byteCount); return sr; } } else { return null; } }
public void Execute() { try { // Create new spatial reference ISpatialReference spatialReference = null; if (this.SRef.ToLowerInvariant().Contains("projcs")) { spatialReference = new ProjectedCoordinateSystemClass(); } else { spatialReference = new GeographicCoordinateSystemClass(); } // Import SpatialReference Definition int bytes2; IESRISpatialReferenceGEN2 gen = (IESRISpatialReferenceGEN2)spatialReference; gen.ImportFromESRISpatialReference(this.SRef, out bytes2); // Create Search Extent IEnvelope extent = new EnvelopeClass(); extent.PutCoords(this.XMin, this.YMin, this.XMax, this.YMax); extent.SpatialReference = spatialReference; // Open Saved Layer File ILayerFile layerFile = new LayerFileClass(); layerFile.Open(this.Path); ILayer layer = layerFile.Layer; layerFile.Close(); // Where clause and list of selected OIDs string where = string.Empty; List <int> ids = new List <int>(); IImageServerLayer imageLayer = null; if (layer is IImageServerLayer) { imageLayer = (IImageServerLayer)layer; // Get Selection Set IFeatureLayerDefinition definition = layer as IFeatureLayerDefinition; if (definition != null) { // Find Selected OIDs if (definition.DefinitionSelectionSet != null) { if (definition.DefinitionSelectionSet.Count > 0) { IEnumIDs emumids = definition.DefinitionSelectionSet.IDs; int id = emumids.Next(); while (id != -1) { ids.Add(id); id = emumids.Next(); } } } // Update Where Clause if (!string.IsNullOrEmpty(definition.DefinitionExpression)) { where = definition.DefinitionExpression; } } } else if (layer is IMosaicLayer) { IMosaicLayer mosaicLayer = (IMosaicLayer)layer; imageLayer = mosaicLayer.PreviewLayer; ITableDefinition tableDefinition = mosaicLayer as ITableDefinition; if (tableDefinition != null) { // Find Selected OIDs if (tableDefinition.DefinitionSelectionSet != null) { if (tableDefinition.DefinitionSelectionSet.Count > 0) { IEnumIDs emumids = tableDefinition.DefinitionSelectionSet.IDs; int id = emumids.Next(); while (id != -1) { ids.Add(id); id = emumids.Next(); } } } // Update Where Clause if (!string.IsNullOrEmpty(tableDefinition.DefinitionExpression)) { where = tableDefinition.DefinitionExpression; } } } // Use FeatureSelected (if any) IFeatureSelection featureSelection = imageLayer as IFeatureSelection; if (featureSelection != null) { if (featureSelection.SelectionSet != null) { if (featureSelection.SelectionSet.Count > 0) { IEnumIDs emumids = featureSelection.SelectionSet.IDs; int id = emumids.Next(); while (id != -1) { ids.Add(id); id = emumids.Next(); } } } } // Get Bands ILongArray bands = new LongArrayClass(); IRasterRenderer rasterRenderer = imageLayer.Renderer; if (rasterRenderer != null) { IRasterRGBRenderer2 rasterRGBRenderer = rasterRenderer as IRasterRGBRenderer2; if (rasterRGBRenderer != null) { bands.Add(rasterRGBRenderer.UseRedBand ? rasterRGBRenderer.RedBandIndex : -1); bands.Add(rasterRGBRenderer.UseGreenBand ? rasterRGBRenderer.GreenBandIndex : -1); bands.Add(rasterRGBRenderer.UseBlueBand ? rasterRGBRenderer.BlueBandIndex : -1); bands.Add(rasterRGBRenderer.UseAlphaBand ? rasterRGBRenderer.AlphaBandIndex : -1); } } // Create Spatial Filter ISpatialFilter spatialFilter = new SpatialFilterClass() { Geometry = extent, SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects, WhereClause = where }; IImageServer imageServer = imageLayer.DataSource as IImageServer; if (imageServer == null) { return; } IImageServer3 imageServer3 = imageServer as IImageServer3; if (imageServer3 == null) { return; } IRecordSet recordSet = imageServer3.GetCatalogItems(spatialFilter); ICursor cursor = recordSet.get_Cursor(false); IFeatureCursor featureCursor = (IFeatureCursor)cursor; IFeature feature = featureCursor.NextFeature(); List <IFeature> list = new List <IFeature>(); int indexCategory = featureCursor.FindField("Category"); while (feature != null) { // Exclude non-primary images (no overviews) if (indexCategory != -1) { int cat = (int)feature.get_Value(indexCategory); if (cat != 1) { feature = featureCursor.NextFeature(); continue; } } // Exclude unselected features if (ids.Count > 0) { int oid = feature.OID; if (!ids.Contains(oid)) { feature = featureCursor.NextFeature(); continue; } } list.Add(feature); feature = featureCursor.NextFeature(); } // If nothing, fire event then exit if (list.Count == 0) { this.OnThumbnailSummary(new SummaryEventArgs()); return; } // Get Full Extent of Features SummaryEventArgs summary = new SummaryEventArgs() { XMin = list.Min(f => f.Shape.Envelope.CloneProject(spatialReference).XMin), YMin = list.Min(f => f.Shape.Envelope.CloneProject(spatialReference).YMin), XMax = list.Max(f => f.Shape.Envelope.CloneProject(spatialReference).XMax), YMax = list.Max(f => f.Shape.Envelope.CloneProject(spatialReference).YMax), Count = list.Count }; // Add Fields IFields fields = featureCursor.Fields; for (int i = 0; i < fields.FieldCount; i++) { IField field = fields.get_Field(i); switch (field.Type) { case esriFieldType.esriFieldTypeBlob: case esriFieldType.esriFieldTypeGeometry: case esriFieldType.esriFieldTypeGlobalID: case esriFieldType.esriFieldTypeGUID: case esriFieldType.esriFieldTypeRaster: case esriFieldType.esriFieldTypeXML: break; case esriFieldType.esriFieldTypeOID: case esriFieldType.esriFieldTypeDate: case esriFieldType.esriFieldTypeDouble: case esriFieldType.esriFieldTypeInteger: case esriFieldType.esriFieldTypeSingle: case esriFieldType.esriFieldTypeSmallInteger: case esriFieldType.esriFieldTypeString: summary.Fields.Add( new Field() { Name = field.Name, Alias = field.AliasName, Type = field.Type } ); break; default: break; } } // Raise Summary Event this.OnThumbnailSummary(summary); // Loop for each feature foreach (IFeature feat in list) { // Project Extent to Current Map Spatial Reference IEnvelope extentMap = feat.Shape.Envelope.CloneProject(spatialReference); int width; int height; if (extentMap.Width > extentMap.Height) { width = this.MaxImageSize; height = Convert.ToInt32((double)this.MaxImageSize * (double)extentMap.Height / (double)extentMap.Width); } else { width = Convert.ToInt32((double)this.MaxImageSize * (double)extentMap.Width / (double)extentMap.Height); height = this.MaxImageSize; } IMosaicRule mosaicRule = new MosaicRuleClass() { MosaicMethod = esriMosaicMethod.esriMosaicLockRaster, LockRasterID = feat.OID.ToString() }; IGeoImageDescription geoImageDescription = new GeoImageDescriptionClass() { BandSelection = bands.Count > 0 ? bands : null, MosaicRule = mosaicRule, Compression = "PNG", Width = width, Height = height, SpatialReference = spatialReference, Extent = extentMap, Interpolation = rstResamplingTypes.RSP_BilinearInterpolation, }; // Assembly MosaicRequest (will be executed in background thread) MosaicRequest mosaicRequest = new MosaicRequest() { MosaicExtractor = this, ImageServer = imageServer3, GeoImageDescription = geoImageDescription, XMin = extentMap.XMin, YMin = extentMap.YMin, XMax = extentMap.XMax, YMax = extentMap.YMax, }; // Add Attributes Names and Values foreach (Field field in summary.Fields) { int index = feat.Fields.FindField(field.Name); if (index < 0) { continue; } mosaicRequest.Attributes.Add(field.Name, feat.get_Value(index)); } // Start Mosaic Request in Background Thread Thread thread = new Thread(new ThreadStart(mosaicRequest.Execute)); MosaicEnvironment.Default.Threads.Add(thread); thread.Start(); } } catch { } }
//将任意坐标系统转换为自定义Albers大地坐标(米) public static IPoint GeoToGra(IPoint point) { IPoint pt = new PointClass(); pt.PutCoords(point.X, point.Y); ISpatialReferenceFactory2 pFact = new SpatialReferenceEnvironmentClass(); //定义地理坐标,由输入的对象决定,也可以自己定义,参考: esriSRGeoCSType IGeographicCoordinateSystem pGCS = new GeographicCoordinateSystemClass(); pGCS = pFact.CreateGeographicCoordinateSystem(point.SpatialReference.FactoryCode); //自定义投影方式 IProjectedCoordinateSystem pProjectedCS = new ProjectedCoordinateSystemClass(); IProjectedCoordinateSystemEdit pProjectedCSEdit = pProjectedCS as IProjectedCoordinateSystemEdit; //定义投影方式,参考: esriSRProjectionType IProjection pProjection = new ProjectionClass(); pProjection = pFact.CreateProjection((int)esriSRProjectionType.esriSRProjection_Albers); //定义投影单位,参考:esriSRUnitType ILinearUnit pUnit = new LinearUnitClass(); pUnit = pFact.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter) as ILinearUnit; //定义其他参数,参考:esriSRParameterType IParameter[] pParm = new IParameter[6]; pParm[0] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseEasting); pParm[0].Value = 0; pParm[1] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseNorthing); pParm[1].Value = 0; pParm[2] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_CentralMeridian); pParm[2].Value = 110; pParm[3] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_StandardParallel1); pParm[3].Value = 25; pParm[4] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_StandardParallel2); pParm[4].Value = 47; pParm[5] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_LatitudeOfOrigin); pParm[5].Value = 0; //设置投影相关信息 object name = "User_Defined_Albers"; object alias = "Albers"; object abbreviation = "Albers"; object remarks = "User_Defined_Albers is the projection"; object usage = ""; object gcs = pGCS; object projectedUnit = pUnit; object projection = pProjection; object parameters = pParm; pProjectedCSEdit.Define(ref name, ref alias, ref abbreviation, ref remarks, ref usage, ref gcs, ref projectedUnit, ref projection, ref parameters); //获取自定义空间参考 ISpatialReference pSpatialRef = pProjectedCS as ISpatialReference; IGeometry pGeometry = (IGeometry)pt; pGeometry.SpatialReference = pGCS as ISpatialReference; //重投影处理 pGeometry.Project(pSpatialRef); return pt; }
public static void cp(IPolygon pPolygon) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Shape文件(*.shp)|*.shp"; saveFileDialog.Title = "新建面shp文件"; saveFileDialog.CheckFileExists = true; saveFileDialog.RestoreDirectory = true; DialogResult dialogResult = saveFileDialog.ShowDialog(); string shpPath; string shpName; IWorkspaceFactory pWorkSpaceFactory = new ShapefileWorkspaceFactory(); if (dialogResult == DialogResult.OK) { IFeatureClass pFeatureClass; string date = DateTime.Now.ToLongDateString().ToString(); //saveFileDialog.FileName = date + "采集的坐标点"; string fileFullName = saveFileDialog.FileName; int index = fileFullName.LastIndexOf("\\"); shpName = fileFullName.Substring(index + 1); shpPath = fileFullName.Substring(0, index); IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkSpaceFactory.OpenFromFile(shpPath, 0); IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pFeatureWorkspace; IGeometryDef pGeometryDef = new GeometryDef(); IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit; pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;//点、线、面什么的 ISpatialReferenceFactory2 ipSpaRefFa = new SpatialReferenceEnvironmentClass(); IGeographicCoordinateSystem ipGeoCorSys = new GeographicCoordinateSystemClass(); ipGeoCorSys = ipSpaRefFa.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); ISpatialReference ipSpaRef = ipGeoCorSys; pGeometryDefEdit.SpatialReference_2 = ipSpaRef; /*if (System.IO.File.Exists(saveFileDialog.FileName)) { if (MessageBox.Show("是否替换原文件?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { pFeatureClass = pFeatureWorkspace.OpenFeatureClass(shpName); IDataset pDataset = (IDataset)pFeatureClass; pDataset.Delete(); } else return; } else { fileFullName = null; return; }*/ //设置字段 double area; IFields pFields = new FieldsClass(); IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields; IField pField = new FieldClass(); IFieldEdit pFieldEdit = (IFieldEdit)pField; pFieldEdit.Name_2 = "SHAPE"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; pFieldEdit.GeometryDef_2 = pGeometryDef; pFieldsEdit.AddField(pField); pField = new FieldClass(); pFieldEdit = (IFieldEdit)pField; pFieldEdit.Name_2 = "面积"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; pFieldsEdit.AddField(pField); //创建shp pWorkspaceEdit.StartEditOperation();//启动编辑 pFeatureClass = pFeatureWorkspace.CreateFeatureClass(shpName, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", ""); pPolygon = new PolygonClass(); IArea s = pPolygon as IArea; area = s.Area; IFeature pfeature = pFeatureClass.CreateFeature(); pfeature.Shape = pPolygon; pfeature.set_Value(pfeature.Fields.FindField("面积"), area.ToString()); pfeature.Store(); pWorkspaceEdit.StopEditOperation(); IFeatureLayer pFeaturelayer = new FeatureLayerClass(); pFeaturelayer.FeatureClass = pFeatureClass; pFeaturelayer.Name = "采集坐标图层"; } }
public void Execute() { try { // Create new spatial reference ISpatialReference spatialReference = null; if (this.SRef.ToLowerInvariant().Contains("projcs")) { spatialReference = new ProjectedCoordinateSystemClass(); } else { spatialReference = new GeographicCoordinateSystemClass(); } // Import SpatialReference Definition int bytes2; IESRISpatialReferenceGEN2 gen = (IESRISpatialReferenceGEN2)spatialReference; gen.ImportFromESRISpatialReference(this.SRef, out bytes2); // Create Search Extent IEnvelope extent = new EnvelopeClass(); extent.PutCoords(this.XMin, this.YMin, this.XMax, this.YMax); extent.SpatialReference = spatialReference; // Open Saved Layer File ILayerFile layerFile = new LayerFileClass(); layerFile.Open(this.Path); ILayer layer = layerFile.Layer; layerFile.Close(); // Where clause and list of selected OIDs string where = string.Empty; List<int> ids = new List<int>(); IImageServerLayer imageLayer = null; if (layer is IImageServerLayer) { imageLayer = (IImageServerLayer)layer; // Get Selection Set IFeatureLayerDefinition definition = layer as IFeatureLayerDefinition; if (definition != null) { // Find Selected OIDs if (definition.DefinitionSelectionSet != null) { if (definition.DefinitionSelectionSet.Count > 0) { IEnumIDs emumids = definition.DefinitionSelectionSet.IDs; int id = emumids.Next(); while (id != -1) { ids.Add(id); id = emumids.Next(); } } } // Update Where Clause if (!string.IsNullOrEmpty(definition.DefinitionExpression)) { where = definition.DefinitionExpression; } } } else if (layer is IMosaicLayer) { IMosaicLayer mosaicLayer = (IMosaicLayer)layer; imageLayer = mosaicLayer.PreviewLayer; ITableDefinition tableDefinition = mosaicLayer as ITableDefinition; if (tableDefinition != null) { // Find Selected OIDs if (tableDefinition.DefinitionSelectionSet != null) { if (tableDefinition.DefinitionSelectionSet.Count > 0) { IEnumIDs emumids = tableDefinition.DefinitionSelectionSet.IDs; int id = emumids.Next(); while (id != -1) { ids.Add(id); id = emumids.Next(); } } } // Update Where Clause if (!string.IsNullOrEmpty(tableDefinition.DefinitionExpression)) { where = tableDefinition.DefinitionExpression; } } } // Use FeatureSelected (if any) IFeatureSelection featureSelection = imageLayer as IFeatureSelection; if (featureSelection != null) { if (featureSelection.SelectionSet != null) { if (featureSelection.SelectionSet.Count > 0) { IEnumIDs emumids = featureSelection.SelectionSet.IDs; int id = emumids.Next(); while (id != -1) { ids.Add(id); id = emumids.Next(); } } } } // Get Bands ILongArray bands = new LongArrayClass(); IRasterRenderer rasterRenderer = imageLayer.Renderer; if (rasterRenderer != null) { IRasterRGBRenderer2 rasterRGBRenderer = rasterRenderer as IRasterRGBRenderer2; if (rasterRGBRenderer != null) { bands.Add(rasterRGBRenderer.UseRedBand ? rasterRGBRenderer.RedBandIndex : -1); bands.Add(rasterRGBRenderer.UseGreenBand ? rasterRGBRenderer.GreenBandIndex : -1); bands.Add(rasterRGBRenderer.UseBlueBand ? rasterRGBRenderer.BlueBandIndex : -1); bands.Add(rasterRGBRenderer.UseAlphaBand ? rasterRGBRenderer.AlphaBandIndex : -1); } } // Create Spatial Filter ISpatialFilter spatialFilter = new SpatialFilterClass() { Geometry = extent, SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects, WhereClause = where }; IImageServer imageServer = imageLayer.DataSource as IImageServer; if (imageServer == null) { return; } IImageServer3 imageServer3 = imageServer as IImageServer3; if (imageServer3 == null) { return; } IRecordSet recordSet = imageServer3.GetCatalogItems(spatialFilter); ICursor cursor = recordSet.get_Cursor(false); IFeatureCursor featureCursor = (IFeatureCursor)cursor; IFeature feature = featureCursor.NextFeature(); List<IFeature> list = new List<IFeature>(); int indexCategory = featureCursor.FindField("Category"); while (feature != null) { // Exclude non-primary images (no overviews) if (indexCategory != -1) { int cat = (int)feature.get_Value(indexCategory); if (cat != 1) { feature = featureCursor.NextFeature(); continue; } } // Exclude unselected features if (ids.Count > 0) { int oid = feature.OID; if (!ids.Contains(oid)) { feature = featureCursor.NextFeature(); continue; } } list.Add(feature); feature = featureCursor.NextFeature(); } // If nothing, fire event then exit if (list.Count == 0) { this.OnThumbnailSummary(new SummaryEventArgs()); return; } // Get Full Extent of Features SummaryEventArgs summary = new SummaryEventArgs() { XMin = list.Min(f => f.Shape.Envelope.CloneProject(spatialReference).XMin), YMin = list.Min(f => f.Shape.Envelope.CloneProject(spatialReference).YMin), XMax = list.Max(f => f.Shape.Envelope.CloneProject(spatialReference).XMax), YMax = list.Max(f => f.Shape.Envelope.CloneProject(spatialReference).YMax), Count = list.Count }; // Add Fields IFields fields = featureCursor.Fields; for (int i = 0; i < fields.FieldCount; i++) { IField field = fields.get_Field(i); switch (field.Type) { case esriFieldType.esriFieldTypeBlob: case esriFieldType.esriFieldTypeGeometry: case esriFieldType.esriFieldTypeGlobalID: case esriFieldType.esriFieldTypeGUID: case esriFieldType.esriFieldTypeRaster: case esriFieldType.esriFieldTypeXML: break; case esriFieldType.esriFieldTypeOID: case esriFieldType.esriFieldTypeDate: case esriFieldType.esriFieldTypeDouble: case esriFieldType.esriFieldTypeInteger: case esriFieldType.esriFieldTypeSingle: case esriFieldType.esriFieldTypeSmallInteger: case esriFieldType.esriFieldTypeString: summary.Fields.Add( new Field() { Name = field.Name, Alias = field.AliasName, Type = field.Type } ); break; default: break; } } // Raise Summary Event this.OnThumbnailSummary(summary); // Loop for each feature foreach (IFeature feat in list) { // Project Extent to Current Map Spatial Reference IEnvelope extentMap = feat.Shape.Envelope.CloneProject(spatialReference); int width; int height; if (extentMap.Width > extentMap.Height) { width = this.MaxImageSize; height = Convert.ToInt32((double)this.MaxImageSize * (double)extentMap.Height / (double)extentMap.Width); } else { width = Convert.ToInt32((double)this.MaxImageSize * (double)extentMap.Width / (double)extentMap.Height); height = this.MaxImageSize; } IMosaicRule mosaicRule = new MosaicRuleClass() { MosaicMethod = esriMosaicMethod.esriMosaicLockRaster, LockRasterID = feat.OID.ToString() }; IGeoImageDescription geoImageDescription = new GeoImageDescriptionClass() { BandSelection = bands.Count > 0 ? bands : null, MosaicRule = mosaicRule, Compression = "PNG", Width = width, Height = height, SpatialReference = spatialReference, Extent = extentMap, Interpolation = rstResamplingTypes.RSP_BilinearInterpolation, }; // Assembly MosaicRequest (will be executed in background thread) MosaicRequest mosaicRequest = new MosaicRequest() { MosaicExtractor = this, ImageServer = imageServer3, GeoImageDescription = geoImageDescription, XMin = extentMap.XMin, YMin = extentMap.YMin, XMax = extentMap.XMax, YMax = extentMap.YMax, }; // Add Attributes Names and Values foreach (Field field in summary.Fields) { int index = feat.Fields.FindField(field.Name); if (index < 0) { continue; } mosaicRequest.Attributes.Add(field.Name, feat.get_Value(index)); } // Start Mosaic Request in Background Thread Thread thread = new Thread(new ThreadStart(mosaicRequest.Execute)); MosaicEnvironment.Default.Threads.Add(thread); thread.Start(); } } catch { } }
//将任意坐标系统转换为自定义Albers大地坐标(米) public static IPoint GeoToGra(IPoint point) { IPoint pt = new PointClass(); pt.PutCoords(point.X, point.Y); ISpatialReferenceFactory2 pFact = new SpatialReferenceEnvironmentClass(); //定义地理坐标,由输入的对象决定,也可以自己定义,参考: esriSRGeoCSType IGeographicCoordinateSystem pGCS = new GeographicCoordinateSystemClass(); pGCS = pFact.CreateGeographicCoordinateSystem(point.SpatialReference.FactoryCode); //自定义投影方式 IProjectedCoordinateSystem pProjectedCS = new ProjectedCoordinateSystemClass(); IProjectedCoordinateSystemEdit pProjectedCSEdit = pProjectedCS as IProjectedCoordinateSystemEdit; //定义投影方式,参考: esriSRProjectionType IProjection pProjection = new ProjectionClass(); pProjection = pFact.CreateProjection((int)esriSRProjectionType.esriSRProjection_Albers); //定义投影单位,参考:esriSRUnitType ILinearUnit pUnit = new LinearUnitClass(); pUnit = pFact.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter) as ILinearUnit; //定义其他参数,参考:esriSRParameterType IParameter[] pParm = new IParameter[6]; pParm[0] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseEasting); pParm[0].Value = 0; pParm[1] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_FalseNorthing); pParm[1].Value = 0; pParm[2] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_CentralMeridian); pParm[2].Value = 110; pParm[3] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_StandardParallel1); pParm[3].Value = 25; pParm[4] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_StandardParallel2); pParm[4].Value = 47; pParm[5] = pFact.CreateParameter((int)esriSRParameterType.esriSRParameter_LatitudeOfOrigin); pParm[5].Value = 0; //设置投影相关信息 object name = "User_Defined_Albers"; object alias = "Albers"; object abbreviation = "Albers"; object remarks = "User_Defined_Albers is the projection"; object usage = ""; object gcs = pGCS; object projectedUnit = pUnit; object projection = pProjection; object parameters = pParm; pProjectedCSEdit.Define(ref name, ref alias, ref abbreviation, ref remarks, ref usage, ref gcs, ref projectedUnit, ref projection, ref parameters); //获取自定义空间参考 ISpatialReference pSpatialRef = pProjectedCS as ISpatialReference; IGeometry pGeometry = (IGeometry)pt; pGeometry.SpatialReference = pGCS as ISpatialReference; //重投影处理 pGeometry.Project(pSpatialRef); return(pt); }