ArcGis空间分析之剖面图
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
ArcGis空间分析之剖面图
剖面图,就是在具有高程值的raster上画一条直线,这条直线上的每个点除了x,y坐标为更具附加了高程值,便可画出高程值随直线的一个曲线图。
高程值只是一个最简单的例子,当raster不是以高程值而是以某个我们想要的值来渲染的时候,这条曲线图便表达的是,随直线变化而变化的某个值的曲线图,开始做这个的时候遇到了一些无法解释的困难,如Com组件错误等,这里参考了韩鹏的<<ArcObject方法>>,这里推荐一下,这是本好书,值得拥有啊,以下是我的代码,我用的是ArcgisEngine来做的,不过ArcgisServer也可以实现
//得到要做剖面分析的面
IRasterLayer layer = this.axMapControl1.Map.get_Layer(0) as IRasterLayer;
IRasterSurface rasterSurf = new RasterSurfaceClass();
rasterSurf.PutRaster(layer.Raster, 0);
ISurface surface = rasterSurf as ISurface;
//得到画的直线
IPolyline inputLine = new PolylineClass();
IPoint start = new PointClass();
start.X = -96.522;
start.Y = 25.589;
inputLine.FromPoint = start;
IPoint end = new PointClass();
end.X = 1.048;
end.Y = 28.664;
inputLine.ToPoint = end;
//用ISurface的InterpolateShape方法,得到这条直线做剖面后的Geometry,方法说明详见帮助
IGeometry OutShape;
object size = new object();
surface.InterpolateShape(inputLine, out OutShape, ref size);
//将结果QI为PointCollection,QI成功显示结果是直线上单一的几个离散点,InterpolateShape会自动将分析的结果直线上选取六个等分的离散点,以这六个点的值来作曲线图
IPointCollection pointCollection = OutShape as IPointCollection;
IMAware maware = pointCollection as IMAware;
maware.MAware = true;
IZAware zaware = pointCollection as IZAware;
zaware.ZAware = true;
IMSegmentation mseg = pointCollection as IMSegmentation;
//设置M的值为距离
mseg.SetMsAsDistance(false);
//建立featureClass,为后面曲线图提供数据
IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
ESRI.ArcGIS.Geodatabase.IWorkspaceName workspaceName =
workspaceFactory.Create("", "MyWorkspace", null, 0);
ESRI.ArcGIS.esriSystem.IName name = (IName)workspaceName;
ESRI.ArcGIS.Geodatabase.IWorkspace inmemWor = (IWorkspace)name.Open();
IFields fields = new FieldsClass();
IFieldsEdit fieldsEdit = fields as IFieldsEdit;
IField oidField = new FieldClass();
IFieldEdit oidFieldEdit = oidField as IFieldEdit;
_2 = "OID";
oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
fieldsEdit.AddField(oidField);
IGeometryDef geometryDef = new GeometryDefClass();
IGeometryDefEdit geometryDefEdit = geometryDef as IGeometryDefEdit;
geometryDefEdit.GeometryType_2 =
ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint;
geometryDefEdit.HasM_2 = true;
geometryDefEdit.HasZ_2 = true;
ISpatialReferenceFactory spatialReferenceFactory = new
SpatialReferenceEnvironmentClass();
ISpatialReference spatialReference
= spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeo CSType.esriSRGeoCS_WGS1984);
ISpatialReferenceResolution spatialReferenceResolution =
(ISpatialReferenceResolution)spatialReference;
spatialReferenceResolution.ConstructFromHorizon();
ISpatialReferenceTolerance spatialReferenceTolerance =
(ISpatialReferenceTolerance)spatialReference;
spatialReferenceTolerance.SetDefaultXYTolerance();
geometryDefEdit.SpatialReference_2 = spatialReference;
IField geometryField = new FieldClass();
IFieldEdit geometryFieldEdit = (IFieldEdit)geometryField;
_2 = "Shape";
geometryFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
geometryFieldEdit.GeometryDef_2 = geometryDef;
fieldsEdit.AddField(geometryField);
IField mField = new FieldClass();
IFieldEdit mFieldEdit = (IFieldEdit)mField;
_2 = "M";
mFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
mFieldEdit.Length_2 = 8;
fieldsEdit.AddField(mField);
IField zField = new FieldClass();
IFieldEdit zFieldEdit = (IFieldEdit)zField;
_2 = "Z";
zFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
zFieldEdit.Length_2 = 8;
fieldsEdit.AddField(zField);
IFieldChecker fieldChecker = new FieldCheckerClass();
IEnumFieldError enumFieldError = null;
IFields validatedFields = null;
fieldChecker.ValidateWorkspace = inmemWor;
fieldChecker.Validate(fields, out enumFieldError, out validatedFields);
IFeatureClass featureClass = (inmemWor as
IFeatureWorkspace).CreateFeatureClass("test", validatedFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
IFeatureCursor cursor = featureClass.Insert(true);
IFeatureBuffer buffer = featureClass.CreateFeatureBuffer();
int count = pointCollection.PointCount;
for (int i = 0; i < count; ++i)
{
IPoint p = pointCollection.get_Point(i);
buffer.Shape = p as IGeometry;
buffer.set_Value(buffer.Fields.FindField("M"), p.M);
buffer.set_Value(buffer.Fields.FindField("Z"), p.Z);
cursor.InsertFeature(buffer);
}
cursor.Flush();
//开始做曲线图
IFeatureLayer featurelayer = new FeatureLayerClass();
featurelayer.FeatureClass = featureClass;
ITable table = featurelayer as ITable;
IDataGraph datagraph = new DataGraphClass();
datagraph.Table = table;
datagraph.FieldSet1 = "Z";
datagraph.FieldSet2 = "M";
IDataGraphProperties proper = datagraph as IDataGraphProperties;
proper.Title = "曲线图";
proper.SubTitle = "跟据Z和M值做的剖面图";
proper.GraphType = esriDataGraphTypeEnum.esriDataGraphTypeLine;
proper.GraphSubtype =
esriDataGraphSubtypeEnum.esriDataGraphSubtypeLine2DSimple;
proper.ShowXAxisLabels = true;
proper.ShowLegend = false;
datagraph.Reload();
datagraph.Draw();
datagraph.ExportToFile("c://victorcxj.jpg");
需要注意的是,如果是在b/s上做剖面图开发,上面的对象都不能用new 而是用serverContext来创建,但我在开发中遇到一个奇怪的问题就是datagraph导不出来图片,我后来把DataGraph用new来创建就可以了,有时候AO的东西真是奇怪到你无法解释。