root / branches / Mobile_Compatible_Hito_1 / libFMap_mobile_shp_driver / src-file / org / gvsig / data / datastores / vectorial / file / shp_util / SHPUtil.java @ 22037
History | View | Annotate | Download (2.52 KB)
1 |
package org.gvsig.data.datastores.vectorial.file.shp_util; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
|
5 |
import org.gvsig.data.datastores.vectorial.file.shp.SHPStore; |
6 |
import org.gvsig.data.datastores.vectorial.file.shp_inst.InstSHPStore; |
7 |
import org.gvsig.data.datastores.vectorial.file.shp_jni.JNISHPStore; |
8 |
import org.gvsig.data.datastores.vectorial.file.shp_mem.MemSHPStore; |
9 |
|
10 |
import es.prodevelop.gvsig.mobile.fmap.driver.vect.shp.ShpReader; |
11 |
|
12 |
/**
|
13 |
* This utility class will contain SHP-related static methods.
|
14 |
*
|
15 |
* @author jldominguez
|
16 |
*
|
17 |
*/
|
18 |
public class SHPUtil { |
19 |
|
20 |
/**
|
21 |
* We will not load in memory if larger than this.
|
22 |
*/
|
23 |
public static int MEMORY_SIZE_LIMIT = 2000000; // approx. 2 megabytes |
24 |
|
25 |
/**
|
26 |
* We will not instantiate in memory if larger than this.
|
27 |
*/
|
28 |
public static int INST_SIZE_LIMIT = 1000000; // approx. 2 megabytes |
29 |
|
30 |
/**
|
31 |
* JNI is expected to work well if vertices per shape is larger than this.
|
32 |
*/
|
33 |
public static int VERTICES_PER_SHAPE_LIMIT = 500; |
34 |
|
35 |
/**
|
36 |
* This method will decide which data store should be used, dependiand on the SHP and
|
37 |
* DBF files metadata.
|
38 |
*
|
39 |
* @param shpfile the shapefile of interest
|
40 |
* @return the string that identifies the data store to be used
|
41 |
*/
|
42 |
public static String chooseShpDataStoreName(File shpfile) { |
43 |
|
44 |
File dbff = org.gvsig.data.datastores.vectorial.file.shp.utils.SHP.getDbfFile(shpfile);
|
45 |
//return ShpReader.getDbfFileRowCount()
|
46 |
|
47 |
long handler = ShpReader.openDbfFile(dbff.getAbsolutePath(), false); |
48 |
int feat_count = ShpReader.getDbfFileRowCount(handler);
|
49 |
int att_count = ShpReader.getDbfFileFieldCount(handler);
|
50 |
ShpReader.closeDbfFile(handler); |
51 |
|
52 |
long file_bytes = (int) shpfile.length(); |
53 |
long total_size = file_bytes + (int) dbff.length(); |
54 |
double est_vertices_count = file_bytes / 20.0; |
55 |
double est_vertices_per_shape = est_vertices_count / feat_count;
|
56 |
|
57 |
|
58 |
// -----------------------------------
|
59 |
// Metadata:
|
60 |
//
|
61 |
// least relevant:
|
62 |
// feat_count = number of features
|
63 |
// att_count = number of attributes
|
64 |
//
|
65 |
// most relevant:
|
66 |
// est_vertices_per_shape = estimated vertices per feature
|
67 |
// total_size = size in bytes of SHP + DBF
|
68 |
// -----------------------------------
|
69 |
|
70 |
if (total_size <= INST_SIZE_LIMIT) {
|
71 |
|
72 |
return InstSHPStore.DATASTORE_NAME;
|
73 |
|
74 |
} else {
|
75 |
if (total_size <= MEMORY_SIZE_LIMIT) {
|
76 |
|
77 |
return MemSHPStore.DATASTORE_NAME;
|
78 |
|
79 |
} else {
|
80 |
|
81 |
if (est_vertices_per_shape >= VERTICES_PER_SHAPE_LIMIT) {
|
82 |
|
83 |
return JNISHPStore.DATASTORE_NAME;
|
84 |
|
85 |
} else {
|
86 |
|
87 |
return SHPStore.DATASTORE_NAME;
|
88 |
|
89 |
} |
90 |
|
91 |
} |
92 |
} |
93 |
} |
94 |
|
95 |
} |