作者:dongyx
倾斜摄影技术是国际摄影测量领域近十几年发展起来的一项高新技术,该技术通过从一个垂直、四个倾斜、五个不同的视角同步采集影像,获取到丰富的建筑物顶面及侧视的高分辨率纹理。它不仅能够真实地反映地物情况,高精度地获取物方纹理信息,还可通过先进的定位、融合、建模等技术,生成真实的三维城市模型。目前很多三维客户都会用到倾斜摄影数据,那么在我们SuperMap iDesktop里面加载的时候都会先加载粗糙层,那么有没有办法只加载精细层呢?下面小编为大家介绍通过Java对倾斜摄影数据配置文件的修改来达到显示层级的修改。
倾斜摄影数据本身是具有LOD层级的,在桌面软件中都是以LOD的方式来加载数据的,但是也有客户想实现加载的倾斜摄影数据显示为精细层,不需要显示粗糙层。下面来看一下倾斜摄影数据OSGB的数据组织结构:
从以上三幅图可以看出倾斜摄影数据中每个tile里面的osgb文件其实是有层级的,要想显示精细层,就必须在配置文件中将tile连接到需要显示的层级的osgb文件中。比如将配置文件中FileName节点修改为显示层级的osgb。
实现代码如下:
private static ArrayList<String> listString = new ArrayList<>();
private static boolean isTrue=false;
private static String osgbName;
private static HashMap<String, HashMap<String, Boolean>> hashMap = new HashMap<String, HashMap<String, Boolean>>();
private static HashMap<String,String> hashMap1 = new HashMap<>();
public static void main(String[] args) {
String directPath = "G:\\ToChuDing\\Data1";
String filePath = "G:\\ToChuDing\\Data1\\Config.scp";
String level = "L"+"16";
String outPath="G:\\ToChuDing\\Data1\\Config6.scp";
getFiles(directPath,level);
getXML(filePath,outPath);
}
private static void getFiles(String path,String level) {
File file = new File(path);
System.out.println(path);
if(!file.exists()){
System.out.println("路径不存在");
}
else {
File fa[] = file.listFiles();
for (int i = 0; i < fa.length; i++)
if (fa[i].isDirectory()) {
File[] fileData = fa[i].listFiles();
if(fileData[1].isDirectory()){
for (int i1 = 0; i1 < fileData.length; i1++) {
if (fileData[i1].isDirectory()) {
File[] filesOSGB = fileData[i1].listFiles();
osgbName = fileData[i1].getName();
for (int k = 0; k < filesOSGB.length; k++) {
if (filesOSGB[k].getName().indexOf(level) != -1) {
osgbName = filesOSGB[k].getName();
isTrue = true;
break;
}
}
if (isTrue) {
hashMap1.put(fa[i].getName()+"/"+fileData[i1].getName(), osgbName);
} else {
hashMap1.put(fileData[i1].getName(), null);
}
}
}
}
else {
File[] filesOSGB = fa[i].listFiles();
osgbName=fa[i].getName();
for (int k = 0; k < filesOSGB.length; k++) {
if (filesOSGB[k].getName().indexOf(level) != -1) {
osgbName = filesOSGB[k].getName();
isTrue = true;
break;
}
}
if (isTrue) {
hashMap1.put(fa[i].getName(),osgbName);
} else {
hashMap1.put(fa[i].getName(),null);
}
}
isTrue = false;
}
}
}
private static void getXML(String filePath,String outPath) {
//1.创建DocumentBuilderFactory对象
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//2.创建DocumentBuilder对象
try {
SAXReader reader = new SAXReader();
Document document = reader.read(new File(filePath));
//获取文档根节点
Element root = document.getRootElement();
Element contactElem = root.element("OSGFiles");//首先要知道自己要操作的节点。
List<Element> contactList = contactElem.elements();
for (Element e:contactList){
List<Element> child = e.elements();
listString.add((String) child.get(0).getData());
String str = (String) child.get(0).getData();
Pattern pattern = Pattern.compile("/");
Matcher findMatcher = pattern.matcher(str);
Matcher findMatcher2 = pattern.matcher(str);
int number = 0;
int count = 0;
while (findMatcher.find()) {
count++;
}
while(findMatcher2.find()) {
number++;
if(number == count){//当“/”第二次出现时停止
break;
}
}
int i = findMatcher2.start();//“/”第二次出现的位置
String strFileName = str.substring(str.indexOf("/")+1,str.indexOf("/",i-1));
Iterator iter = hashMap1.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
if(entry.getKey().equals(strFileName)){
if (entry.getValue()!=null) {
String result = hashMap1.get(strFileName);
String name = "./"+strFileName+"/"+result;
child.get(0).setText(name);
}
}
}
FileOutputStream out = new FileOutputStream(outPath);
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("utf-8");
XMLWriter writer = new XMLWriter(out,format);
writer.write(document);
writer.close();
}
System.out.println("生成配置文件成功");
} catch (Exception e) {
e.printStackTrace();
}
}
结果对比如下:
原始粗糙层:
显示16层级: