Data optimized
Overview
The characteristics of mobile devices, putting forward higher requirements of map data running on mobile devices. This paper introduces two methods of data processing, which is to improve mobile map application experience.
1) The image data optimization method of transferring multiband image to single band, without affecting the display effect of the image data in the mobile terminal, improving the performance of browsing mobile terminal image data.
2) Creating the vector data optimization method of spatial index, by establishing data structure to improve the efficiency of spatially querying and accessing data, improving the performance of browsing mobile terminal vector data.
Two optimization methods, supporting adopting the way of optimizing on the desktop to realize, the used tool is SuperMap iDesktop 9D. In addition, using SuperMap iMobile 9D by coding on the mobile terminal, can also realize two optimization.
Optimizing data on the desktop
2.1Image data optimization
"option"function, is used to control whether the vector layer can be optional, namely whether the object of layer can be selected. The image data is a common data type in the mobile, transferring multiband image to single band, improving the operation performance of mobile terminal image data
2.1.1Importing image data
If the image data is independent file, the working space where the image data locate or data source can be opened by importing.
In the "workspace manager" on the left of interface, choosing corresponding data source name, right clicking, selecting "import data set", open the " import data " dialog box By the "add file" button (the location shown below ), adding the image data sets, pay attention to remember coding type, the processed data is to ensure to be the same with the coding type of the original data. The image data
whose band importing mode is "multiband" is needed only for processing, if not multiband here, it does not apply in this method. Clicking on the “import” button, realizing to import.
Figure 1 “ import data " dialog box 2.1.2Viewing image data attributes
Choosing the imported image data set in the last step, right clicking, choosing "attributes", viewing the data sets attributes, select "image" tab in the attributes box, viewing the raster tile attributes. Running image data efficiently on the mobile terminal, recommended value of the raster tile is 256*256, when outputting image data sets in the next, correspondingly setting according to the value.
Figure 2 viewing image data attributes 2.1.3Exporting image data set
In the "workspace manager", double clicking the imported image data set, adding it to new map window. In the map window, right clicking, selecting "exporting is image data set", opening “ exporting is image data set” dialog box. Setting"resolution”, the value is the result of "recommended value of the raster tile 256/ the size of original image raster tile". (For example: The original image raster tile is 128*128, the resolution is 256/128=2). Setting "encoding type", encoding type should be consistent with the original image. After setting it, clicking on the "OK ", completing to export image data.
Figure 3 Exporting image data set
Viewing the attributes of new data, finding that the raster tile has been 256*256.
Figure 4 Exporting data set attributes
The optimized image data set, after completely exporting, the original data has been ineffective, it can be deleted by right-clicking and choosing ?delete data set?.
2.1.4Setting image data pyramid
In order to accelerate the display speed of the new data set, it is needed to create image pyramid for the new data set.
In the "workspace manager", double clicking the image data, adding it to new map window, in this process, it will pop up a prompt as shown below, selecting “yes“, to create the image pyramid.
Figure 5 Creating image pyramid prompt box
Figure 6 "Image pyramid management ” dialog box
At this point, the optimization of image data has been completed, the image data set can be stored in the data source only, also can be added to the map. When using, it is only needed to copy the workspace where the optimized image data set locate or data source to mobile devices, then using SuperMap iMobile to open the corresponding contents, users can experience the optimized image data set smoothly applying on the mobile terminal.
2.2Vector data optimization
Using SuperMap Desktop software SuperMap iDesktop realizes to create spatial index. It is recommended to use iDesktop 8.1.0 and higher version. Note here: The version lower than 8.1.0 only supports to create a spatial index for vector data set whose record number is greater than 1000.
Right clicking the corresponding data set name in the?workspace manager?, choosing
"reconstruct spatial index", opening the spatial index management ” dialog box. Choosing the data sets to be processed, selecting index type, the single data set can be independently set (the location shown below ?) after completely setting, clicking “OK”.
Figure 7 "Spatial index management “ dialog box
After completely optimizing, copying the workspace where the vector data set locate or data source to mobile devices, using SuperMap iMobile to open corresponding data to experience the optimized effect.
The method to optimize data in mobile
3.1Optimization of image data
Optimizing multi-band image data can be chieved both in iDesktop and SuperMap iMobile.
The required jar packets are: com.supermap.data.jarand com.supermap.mapping.jar.
Reference codes are:
String sdcard =
android.os.Environment.getExternalStorageDirectory().getAbsolutePath().toString();
//Set license path
Environment.setLicensePath(sdcard+"/SuperMap/license/");
//InitialiMobilWork environment
Environment.initialization(this);
String strTiffPath = sdcard + "/SampleData/YX.tif"; //TIFF Image path String strUDBPath = sdcard + "/SampleData/testISA.udb"; //Datasource path Workspace workspace = new Workspace();
File file = new File(strTiffPath);
if (file.exists() == true) { //Existed TIFF Image data File fileUDB = new File(strUDBPath);
Datasource datasource = null;
if (!fileUDB.exists()) { //If no datasource, create a datasource
// create a datasource
DatasourceConnectionInfo dsInfo = new DatasourceConnectionInfo();
dsInfo.setServer(strUDBPath);
dsInfo.setEngineType(EngineType.UDB);
datasource = workspace.getDatasources().create(dsInfo);
}
else //If datasource existed, open the datasource {
DatasourceConnectionInfo dsInfo = new DatasourceConnectionInfo();
dsInfo.setServer(strUDBPath);
dsInfo.setEngineType(EngineType.UDB);
datasource = workspace.getDatasources().open(dsInfo);
}
if(datasource != null){
// Import Tiff dataset
String strTmpIMG = "img"; //Original TIFF image dataset name String strIMG = "img2"; //Optimized TIFF image dataset name
if (datasource.getDatasets().contains(strTmpIMG)) { //If there is an original dataset included in datasource, delete the dataset.
datasource.getDatasets().delete(strTmpIMG);
}
if (datasource.getDatasets().contains(strIMG)) { //If there is an optimized dataset
included in datasource, delete the dataset.
datasource.getDatasets().delete(strIMG);
}
boolean result = false;
try {//Import TIFF data
ImportSettingTIF settingTif = new ImportSettingTIF();
settingTif.setImportingAsGrid(false);
settingTif.setMultiBandImportMode(MultiBandImportMode.MULTIBAND);
settingTif.setSourceFileCharset(Charset.UTF8);
settingTif.setSourceFilePath(strTiffPath);
settingTif.setTargetDatasetName(strTmpIMG);
settingTif.setTargetDatasource(datasource);
result = DataConversion.importTIF(settingTif);
} catch(Exception e) { e.printStackTrace();
}
if (result) {
DatasetImage datasetImage =
(DatasetImage)datasource.getDatasets().get(strTmpIMG);
datasetImage.buildPyramid(); //Create image pyramid
/ Create a new map
Map mapTmp = new Map();
mapTmp.setWorkspace(workspace);
mapTmp.getLayers().add(datasource.getDatasets().get(strTmpIMG), true);
//Get height, width and external rectangle of image data int nWidth = (int)datasetImage.getWidth();
int nHeight = (int)datasetImage.getHeight();
Rectangle2D bounds = datasetImage.getBounds();
//Set map size and range
mapTmp.setImageSize( nWidth/2, nHeight/2);
mapTmp.setViewBounds(datasetImage.getBounds());
//Set resolution
double resolution = bounds.getHeight() / datasetImage.getHeight() * 2;
if (datasource.getDatasets().contains(strIMG)){
datasource.getDatasets().delete(strIMG);
}
//Compress image dataset
DatasetImage dsImageOutput = mapTmp.outputMapToDatasetImage(datasource, strIMG, resolution, bounds, datasetImage.getEncodeType());
if( dsImageOutput != null){
dsImageOutput.close(); //Close dataset
dsImageOutput.buildPyramid(); //Create image pyramid }
else{
System.out.println("Failed to compress image dataset.");
}
//Close map,Release resource mapTmp.close();
mapTmp.dispose();
} else{
System.out.println("Failed to import image dataset.");
}
System.out.println("Failed to get datasource.");
} } else{
System.out.println("Didn't find image dataset.");
}
setContentView(R.layout.activity_main);
3.2Optimize vector dataset
Only the vector dataset that record number is more than 1000 can be created spatial index.
The required packets jarare: com.supermap.data.jar and com.supermap.mapping.jar.
Reference codes are:
//Gets datasource applied by the dataset creating spatial index
Datasource datasource = m_workSpace.getDatasources().get(0);
//Gets the dataset which will be used to create spatial index.
DatasetVector datasetVector = (DatasetVector) datasource.getDatasets().get( "road");
//Determine whether re-building spatial index is necessary
if(datasetVector.isSpatialIndexDirty()){//1.No spatial index, record number is more than 1000 2Existed spatial index, the index may need to be rebuilt after the data process is modified.
//Gets index type of current dataset
SpatialIndexType type = datasetVector.getSpatialIndexType();
//If current dataset has no index, create spatial index
if(type.value() == SpatialIndexType.NONE.value()){
//Close dataset
datasetVector.close();
//Create spatial index
result = datasetVector.buildSpatialIndex(SpatialIndexType.RTREE);
if(!result) {
System.out.println("Failed to create spatial index!");
} else{
System.out.println("Creating spatial index is successful.");
} }
else{//If current dataset has index, it needs to be rebuilt, after modifying the data process, the index may need to be rebuilt.
//Close dataset
datasetVector.close();
//Rebuilt spatial index
result = datasetVector.reBuildSpatialIndex();
if(!result) {
System.out.println("Failed to rebuild spatial index!");
} else{
System.out.println("Rebuilding spatial index is successful!");
} } }
m_mapControl.getMap().refresh();