新浪博客

Cass7.0读取已有的分幅影像生成对应的图幅拼接表

2016-12-06 20:38阅读:
前提:分幅影像图幅名为左下角坐标命名,不能为有带号的图号,X6位,Y7位。不能为X8位,Y7位。例如“3080-400.tif”图幅比例尺清楚。
操作:
1、在VS2005中(C#语言)编写代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace TK
{
///
/// 关于TK的一些操作
///
public class MakeTK
{
// 读取文件夹下的tif影像,在CAD中制作标准的图幅拼接表,图层'TK',样式按照CASS确定。
[CommandMethod('TifToTK')]
public void TifToTK()
{
Database db = HostApplicationServices.WorkingDatabase;//获取当前数据库
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
//提示输入比例尺
PromptDoubleOptions optDouble = new PromptDoubleOptions('请输入成图比例尺:');
optDouble.AllowNegative = false;//不允许输入负数
optDouble.DefaultValue = 1000;//设置默认值
PromptDoubleResult resDou = ed.GetDouble(optDouble);

double scan = 0.0;
//如果输入正确
if (resDou.Status == PromptStatus.OK)
{
scan = resDou.Value;
}
//string[] names=readTifNames();
FolderBrowserDialog fbd = new FolderBrowserDialog();//文件夹浏览对话框
DialogResult result = fbd.ShowDialog();//显示对话框
string[] fileName = null;
string pathName=null;
if (result == DialogResult.OK)//如果用户选择了确定按钮
{
pathName = fbd.SelectedPath;//用户选择的文件夹
//获取所选择文件夹中的tif文件
fileName = Directory.GetFiles(pathName, '*.tif', SearchOption.AllDirectories);
}

//存放图幅号左下角坐标
List list = new List();

list=GetNum(fileName, pathName);

//以下是画图操作
using (Transaction trans = db.TransactionManager.StartTransaction())
{
//显示绘画内容
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);//以读的方式打开块表
//以写的方式打开模型空间块表记录
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

//创建新的图层,名称为TK
string layerName = 'TK';
if (AddLayer(db, layerName) != ObjectId.Null)
SetCurrentLayer(db, layerName);

//定义边框和文字
List boundarys = new List();
List texts = new List();

for (int i = 0; i < list.Count/2; i++)
{
//图形左下角和右上角坐标
Point2d startPoint = new Point2d(list[2 * i + 1], list[2 * i]);//左下角坐标
//Point2d endPoint = new Point2d(list[2 * i + 1] + scan, list[2 * i] + scan);//右上角坐标

//多段线绘制
Polyline rectangle = new Polyline();
boundarys.Add(CreateRectangle(rectangle, startPoint, scan, layerName));

//文字绘制
//DBText text = new DBText();//创建一个单行文字
//文字内容
string contain = XYToString(startPoint);
//text.TextString = XYToString(startPoint);
//文字样式
texts.Add(TextProperties(db, contain , scan, startPoint,layerName ));

}


//将图形对象的信息添加到块表记录中,并返回ObjectId对象
foreach (Polyline boundary in boundarys)

我的更多文章

下载客户端阅读体验更佳

APP专享