package ArcGISServer;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
public class CArcGISTilePackage extends CArcGISPackageConstnt {
protected String m_sErrorMsg = "OK";
protected String m_sPackagePath;
protected CArcGISPackageMetaData m_aArcGISPackageMetaData = new CArcGISPackageMetaData();
protected CConfFile m_CONF;
public static void main(String[] args) {
DecimalFormat df = new DecimalFormat("#.00");
String aPackFileName = "D:\\ArcGISTilesData\\3fjTMdataRename.zip";
CArcGISTilePackage aArcGISTilePackage =new CArcGISTilePackage();
boolean bOK = aArcGISTilePackage.Open(aPackFileName);
if(!bOK) {
String sMsg = aArcGISTilePackage.GetErrorMsg();
System.out.println(sMsg);
}
CArcGISPackageMetaData arcGISPackageMetaData = aArcGISTilePackage.GetPackageMetaData();
if(null == arcGISPackageMetaData) {
String sMsg = aArcGISTilePackage.GetErrorMsg();
System.out.println(sMsg);
}
int nTotalLevel = arcGISPackageMetaData.GetLevelCount();
for(int i = 0 ;i < nTotalLevel;i++ ) {
CLevelData levelData = arcGISPackageMetaData.GetLevelData(i);
System.out.println("级别:" + i);
System.out.print("起始行列号:");
System.out.print(levelData.m_nLevelRowColExtent.m_nStartRow + " -- " + levelData.m_nLevelRowColExtent.m_nEndRow);
System.out.print(" ");
System.out.println(levelData.m_nLevelRowColExtent.m_nStartCol + " -- " + levelData.m_nLevelRowColExtent.m_nEndCol);
System.out.print("级别的坐标范围:");
System.out.print(df.format(levelData.m_dLevelCoordinateExtent.m_dMinX) + " -- " + df.format(levelData.m_dLevelCoordinateExtent.m_dMaxX));
System.out.print(" ");
System.out.println(df.format(levelData.m_dLevelCoordinateExtent.m_dMinY) + " -- " + df.format(levelData.m_dLevelCoordinateExtent.m_dMaxY));
int a = (int)Math.floor(107648 / Math.pow(2, 18-i));
int b = (int)Math.floor(213376 / Math.pow(2, 18-i));
System.out.println("输入的行列号:" + a + " " + b);
CCoordinateExtent tileExtent = levelData.GetTileExtent(a, b);
System.out.print("切片坐标范围:");
System.out.print(df.format(tileExtent.m_dMinX) + " -- " + df.format(tileExtent.m_dMaxX));
System.out.print(" ");
System.out.println(df.format(tileExtent.m_dMinY) + " -- " + df.format(tileExtent.m_dMaxY));
levelData.GetTileData((tileExtent.m_dMinX + tileExtent.m_dMaxX) / 2
, (tileExtent.m_dMinY + tileExtent.m_dMaxY) / 2);
System.out.println();
}
System.exit(0);
}
public String GetErrorMsg(){return m_sErrorMsg;}
boolean Open(String packagePath) {
boolean bStatus = true;
m_sPackagePath = packagePath;
try {
File file = new File(m_sPackagePath);
if (!file.exists())
throw new Exception("FILE NO EXIST");
ZipFile zf = new ZipFile(file);
bStatus = ReadConfigeFileName(zf);
if (!bStatus) return bStatus;
bStatus = ReadPackageMetaData(zf);
} catch (ParserConfigurationException e) {
bStatus = false;
m_sErrorMsg = e.toString();
e.printStackTrace();
} catch (SAXException e) {
bStatus = false;
m_sErrorMsg = e.toString();
e.printStackTrace();
} catch (ZipException e) {
bStatus = false;
m_sErrorMsg = e.toString();
e.printStackTrace();
} catch (IOException e) {
bStatus = false;
m_sErrorMsg = e.toString();
e.printStackTrace();
} catch(Exception e) {
bStatus = false;
m_sErrorMsg = e.toString();
e.printStackTrace();
}
return bStatus;
}
protected boolean ReadConfigeFileName(ZipFile zf) throws Exception {
boolean bStatus = true;
m_CONF = new CConfFile();
InputStream inputStream;
Enumeration entries = zf.entries();
String confFileEntry = "";
while (entries.hasMoreElements()){
Object ele = entries.nextElement();
if(ele.toString().contains("conf.xml")){
confFileEntry = ele.toString();
break;
}
}
ZipEntry ze = zf.getEntry(confFileEntry);
inputStream = zf.getInputStream(ze);
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(inputStream));
InputSource inputSource = new InputSource(bufferedReader);
DocumentBuilder db;
Document document;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
db = dbf.newDocumentBuilder();
document = db.parse(inputSource);
//遍历TileCacheInfo,获取切片包的行列号
NodeList TileCacheInfoList = document.getElementsByTagName("TileCacheInfo");
for (int i=0; i<TileCacheInfoList.getLength(); i++){
Node TileCacheInfo = TileCacheInfoList.item(i);
NodeList Ranks = TileCacheInfo.getChildNodes();
for (int j=0; j<Ranks.getLength(); j++) {
if (Ranks.item(j).getNodeType() == Node.ELEMENT_NODE) {
if (Ranks.item(j).getNodeName().equals("TileRows"))
m_CONF.nTileRows = Integer.parseInt(Ranks.item(j).getFirstChild().getNodeValue());
else if (Ranks.item(j).getNodeName().equals("TileCols"))
m_CONF.nTileCols = Integer.parseInt(Ranks.item(j).getFirstChild().getNodeValue());
if (m_CONF.nTileRows != 0 && m_CONF.nTileCols != 0) break;
}
}
}
//遍历TileOrigin,获取原点坐标
NodeList TileOriginList = document.getElementsByTagName("TileOrigin");
for (int i = 0; i < TileOriginList.getLength(); i++) {
Node TileOrigin = TileOriginList.item(i);
NodeList Origins = TileOrigin.getChildNodes();
for (int j = 0; j < Origins.getLength(); j++) {
if (Origins.item(j).getNodeType() == Node.ELEMENT_NODE) {
if (Origins.item(j).getNodeName().equals("X"))
m_CONF.dOriginX = Double.parseDouble(Origins.item(j).getFirstChild().getNodeValue());
if (Origins.item(j).getNodeName().equals("Y"))
m_CONF.dOriginY = Double.parseDouble(Origins.item(j).getFirstChild().getNodeValue());
if (m_CONF.dOriginX != 0 && m_CONF.dOriginY != 0)break;
}
}
}
//遍历LODInfo子节点,获取每个level对应的Resolution
double Resolution = 0.0;
NodeList LODInfoList = document.getElementsByTagName("LODInfo");
for (int i = 0; i < LODInfoList.getLength(); i++) {
Node LODInfo = LODInfoList.item(i);
NodeList LODs = LODInfo.getChildNodes();
for (int j = 0; j < LODs.getLength(); j++) {
if (LODs.item(j).getNodeType() == Node.ELEMENT_NODE && LODs.item(j).getNodeName().equals("Resolution"))
评论3
最新资源