Revision 742 org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/gvsig/javadocs/scripting/gvsig.java
gvsig.java | ||
---|---|---|
1 | 1 |
package scripting; |
2 | 2 |
|
3 |
import org.cresques.cts.IProjection; |
|
4 |
import org.gvsig.fmap.dal.DataStore; |
|
3 | 5 |
import org.gvsig.fmap.dal.feature.FeatureType; |
4 | 6 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
7 |
import org.gvsig.scripting.app.extension.ScriptingExtension; |
|
5 | 8 |
|
6 | 9 |
/** |
7 | 10 |
* Representa al modulo python "gvsig". |
8 |
* |
|
9 |
* Es el modulo base que nos facilita el acceso a todos |
|
10 |
* los componentes de gvSIG. |
|
11 | 11 |
* |
12 |
* Puede encontrar un modelo simplificado de objetos mas usadas en
|
|
13 |
* <a href="../doc-files/simplified-object-model.html">Modelo simplificado de objetos</a>
|
|
12 |
* Es el modulo base que nos facilita el acceso a todos los componentes de
|
|
13 |
* gvSIG.
|
|
14 | 14 |
* |
15 |
* |
|
16 | 15 |
*/ |
17 | 16 |
public class gvsig { |
18 | 17 |
|
19 |
/** |
|
20 |
* Returns a new and empty attributes definition. |
|
21 |
* |
|
22 |
* @deprecated use createFeatureType instead |
|
23 |
*/ |
|
24 |
public static FeatureType createSchema() { |
|
25 |
return null; |
|
26 |
} |
|
27 |
|
|
28 |
/** |
|
29 |
* Returns a new and empty attributes definition based in an |
|
30 |
* existing schema. |
|
31 |
* |
|
32 |
* @deprecated use createFeatureType instead |
|
33 |
*/ |
|
34 |
public static FeatureType createSchema(FeatureType schema) { |
|
35 |
return null; |
|
36 |
} |
|
37 |
|
|
38 |
/** |
|
39 |
* Returns a new and empty attributes definition. |
|
40 |
* |
|
41 |
*/ |
|
42 |
public static FeatureType createFeatureType() { |
|
43 |
return null; |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* Returns a new and empty attributes definition based in an |
|
48 |
* existing schema. |
|
49 |
* |
|
50 |
*/ |
|
51 |
public static FeatureType createFeatureType(FeatureType schema) { |
|
52 |
return null; |
|
53 |
} |
|
18 |
public static int LOGGER_INFO = ScriptingExtension.INFO; |
|
19 |
public static int LOGGER_WARN = ScriptingExtension.WARN; |
|
20 |
public static int LOGGER_ERROR = ScriptingExtension.ERROR; |
|
54 | 21 |
|
55 |
/** |
|
56 |
* Create a new layer with the specified parameters. |
|
57 |
* |
|
58 |
* The paramaters "..." are used to connect to the server type and |
|
59 |
* create the layer. |
|
60 |
* |
|
61 |
* Valid values of server type are: |
|
62 |
* - FilesystemExplorer |
|
63 |
* - TODO |
|
64 |
* |
|
65 |
* Valid values of layer type are: |
|
66 |
* - Shape |
|
67 |
* - TODO |
|
68 |
* |
|
69 |
* Excamples of use: |
|
70 |
* TODO |
|
71 |
* |
|
72 |
* @param schema the schema to use to create la layer. |
|
73 |
* @param serverType The server type (filesystem, BBDD, ...) |
|
74 |
* @param layerType The layer type to create (Shape, ...) |
|
75 |
* |
|
76 |
*/ |
|
77 |
public static FLayer creaetLayer(FeatureType schema, String serverType, String layerType, Object... parameters) { |
|
78 |
return null; |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Create a new layer with the specified parameters. |
|
83 |
* |
|
84 |
* Use as default serverType the "FilesystemExplorer". |
|
85 |
* |
|
86 |
*/ |
|
87 |
public static FLayer creaetLayer(FeatureType schema, String layerType, Object... parameters) { |
|
88 |
return null; |
|
89 |
} |
|
22 |
/** |
|
23 |
* Returns a new and empty attributes definition. |
|
24 |
* |
|
25 |
* @return the new FeatureType |
|
26 |
*/ |
|
27 |
public static FeatureType createFeatureType() { |
|
28 |
return null; |
|
29 |
} |
|
90 | 30 |
|
91 |
/** |
|
92 |
* Load an existing shape file in the current view. |
|
93 |
* |
|
94 |
* @param path path to the shape file to load |
|
95 |
* @param projection to use to load the shape file |
|
96 |
* @return |
|
97 |
* |
|
98 |
*/ |
|
99 |
public static FLayer loadShapeFile(String path, String projection) { |
|
100 |
return null; |
|
101 |
} |
|
102 |
|
|
103 |
/** |
|
104 |
* Load an existing shape file in the current view. |
|
105 |
* |
|
106 |
* Use as default projection "CRS:84" |
|
107 |
* |
|
108 |
* @param path path to the shape file to load |
|
109 |
* @return |
|
110 |
* |
|
111 |
*/ |
|
112 |
public static FLayer loadShapeFile(String path) { |
|
113 |
return null; |
|
114 |
} |
|
115 |
|
|
116 |
/** |
|
117 |
* Load an existing layer and return it. |
|
118 |
* |
|
119 |
* Valid values of layer type are: |
|
120 |
* - Shape |
|
121 |
* - TODO |
|
122 |
* |
|
123 |
* @param layerType |
|
124 |
* @param <error> |
|
125 |
* @return |
|
126 |
* |
|
127 |
*/ |
|
128 |
public static FLayer loadLayer(String layerType, Object... parameters) { |
|
129 |
return null; |
|
130 |
} |
|
131 |
|
|
132 |
|
|
31 |
/** |
|
32 |
* Returns a new and empty attributes definition based in an existing |
|
33 |
* FeatureType. |
|
34 |
* |
|
35 |
* All attributes in the feature type pased as parameters are created in the |
|
36 |
* new definition |
|
37 |
* |
|
38 |
* @param featureType from the new attributes are copied |
|
39 |
* @return The new FeatureType |
|
40 |
*/ |
|
41 |
public static FeatureType createFeatureType(FeatureType featureType) { |
|
42 |
return null; |
|
43 |
} |
|
133 | 44 |
|
134 |
/* |
|
135 |
def createShape(definition, filename, geometryType, CRS="CRS:84"): |
|
136 |
""" |
|
137 |
Return new shape layer |
|
138 |
:param definition: layer data definition |
|
139 |
:type definition: Schema |
|
140 |
:param filename: absolute path for shape files. |
|
141 |
:type filename: string |
|
142 |
:param geometryType: geometry type for shape |
|
143 |
:type geometryType: string |
|
144 |
:return: new shape layer |
|
145 |
:rtype: Layer |
|
146 |
""" |
|
147 |
return createLayer( |
|
148 |
definition, |
|
149 |
"FilesystemExplorer", |
|
150 |
"Shape", |
|
151 |
shpFile=filename, |
|
152 |
CRS=CRS, |
|
153 |
geometryType = geometryType |
|
154 |
) |
|
45 |
/** |
|
46 |
* Create a new layer with the specified parameters. |
|
47 |
* |
|
48 |
* The paramaters are used to connect to the server type and create the |
|
49 |
* layer. These parameters are specific of each type of layer. |
|
50 |
* |
|
51 |
* Valid values of server type are: |
|
52 |
* <ul> |
|
53 |
* <li>FilesystemExplorer</li> |
|
54 |
* <li>PostgreSQLExplorer</li> |
|
55 |
* <li>WFSServerExplorer</li> |
|
56 |
* <li>Wms Store</li> |
|
57 |
* <li>...</li> |
|
58 |
* </ul> |
|
59 |
* |
|
60 |
* Valid values of layer type are: |
|
61 |
* <ul> |
|
62 |
* <li>Shape</li> |
|
63 |
* <li>Dbf</li> |
|
64 |
* <li>DXF</li> |
|
65 |
* <li>DGN</li> |
|
66 |
* <li>DWG</li> |
|
67 |
* <li>JExcel</li> |
|
68 |
* <li>PostgreSQL</li> |
|
69 |
* <li>WFSStore</li> |
|
70 |
* <li>Gdal Store</li> |
|
71 |
* <li>...</li> |
|
72 |
* </ul> |
|
73 |
* |
|
74 |
* Excamples of use:<br> |
|
75 |
* <code> |
|
76 |
* TODO |
|
77 |
* </code> |
|
78 |
* |
|
79 |
* @param schema the schema to use to create la layer. |
|
80 |
* @param serverType The server type (filesystem, BBDD, ...) |
|
81 |
* @param layerType The layer type to create (Shape, ...) |
|
82 |
* @param parameters the specific parameters to create the new layer |
|
83 |
* @return the new created layer |
|
84 |
* |
|
85 |
*/ |
|
86 |
public static FLayer creaetLayer(FeatureType schema, String serverType, String layerType, Object... parameters) { |
|
87 |
return null; |
|
88 |
} |
|
155 | 89 |
|
156 |
def createTable(schema, servertype, tableType=None, **parameters): |
|
157 |
"""Creates a new Table document""" |
|
158 |
if tableType == None: |
|
159 |
tableType = servertype |
|
160 |
servertype = "FilesystemExplorer" |
|
90 |
/** |
|
91 |
* Create a new layer with the specified parameters. |
|
92 |
* |
|
93 |
* Use as default serverType the "FilesystemExplorer". |
|
94 |
* |
|
95 |
* @param schema |
|
96 |
* @param layerType |
|
97 |
* @param parameters |
|
98 |
* @return |
|
99 |
*/ |
|
100 |
public static FLayer creaetLayer(FeatureType schema, String layerType, Object... parameters) { |
|
101 |
return null; |
|
102 |
} |
|
161 | 103 |
|
162 |
try: |
|
163 |
application = ApplicationLocator.getManager() |
|
164 |
datamanager = application.getDataManager() |
|
165 |
|
|
166 |
server_parameters = datamanager.createServerExplorerParameters(servertype) |
|
167 |
copyToDynObject(parameters, server_parameters) |
|
104 |
/** |
|
105 |
* Load an existing shape file in the current view. |
|
106 |
* |
|
107 |
* @param path path to the shape file to load |
|
108 |
* @param projection to use to load the shape file |
|
109 |
* @return |
|
110 |
* |
|
111 |
*/ |
|
112 |
public static FLayer loadShapeFile(String path, String projection) { |
|
113 |
return null; |
|
114 |
} |
|
168 | 115 |
|
169 |
server = datamanager.openServerExplorer(servertype, server_parameters) |
|
170 |
|
|
171 |
store_parameters = server.getAddParameters(tableType) |
|
172 |
copyToDynObject(parameters, store_parameters) |
|
173 |
store_parameters.setDefaultFeatureType(schema()) |
|
174 |
|
|
175 |
server.add(tableType, store_parameters, True) |
|
116 |
/** |
|
117 |
* Load an existing shape file in the current view. |
|
118 |
* |
|
119 |
* Use as default projection "CRS:84" |
|
120 |
* |
|
121 |
* @param path path to the shape file to load |
|
122 |
* @return |
|
123 |
* |
|
124 |
*/ |
|
125 |
public static FLayer loadShapeFile(String path) { |
|
126 |
return null; |
|
127 |
} |
|
176 | 128 |
|
177 |
store = datamanager.openStore(tableType, store_parameters) |
|
178 |
|
|
179 |
return store |
|
180 |
|
|
181 |
except Throwable, ex: |
|
182 |
raise RuntimeException("Can't create table, "+ str(ex)) |
|
183 |
|
|
184 |
def createDBF(definition, DbfFile, CRS="CRS:84"): |
|
185 |
""" |
|
186 |
Creates a new dbf document |
|
187 |
:param definition: layer data definition |
|
188 |
:type definition: Schema |
|
189 |
:param DbfFile: absolute path for shape files. |
|
190 |
:type DbfFile: string |
|
191 |
:return: new dbf |
|
192 |
:rtype: Table |
|
193 |
""" |
|
194 |
return createTable( |
|
195 |
definition, |
|
196 |
"FilesystemExplorer", |
|
197 |
"DBF", |
|
198 |
DbfFile=DbfFile, |
|
199 |
CRS=CRS, |
|
200 |
) |
|
129 |
/** |
|
130 |
* Load an existing layer and return it. |
|
131 |
* |
|
132 |
* Valid values of layer type are: - Shape - TODO |
|
133 |
* |
|
134 |
* @param layerType |
|
135 |
* @param parameters |
|
136 |
* @return |
|
137 |
* |
|
138 |
*/ |
|
139 |
public static FLayer loadLayer(String layerType, Object... parameters) { |
|
140 |
return null; |
|
141 |
} |
|
201 | 142 |
|
143 |
/** |
|
144 |
* Send a message to the log system. |
|
145 |
* |
|
146 |
* The values of mode are: |
|
147 |
* <ul> |
|
148 |
* <li>LOGGER_INFO</li> |
|
149 |
* <li>LOGGER_WARN</li> |
|
150 |
* <li>LOGGER_ERROR</li> |
|
151 |
* </ul> |
|
152 |
* |
|
153 |
* @param msg to send to log |
|
154 |
* @param mode message type, is optional with defaul of LOGGER_INFO. |
|
155 |
* @param exception an exception to log, is optional. |
|
156 |
*/ |
|
157 |
public static void logger(String msg, int mode, Throwable exception) { |
|
202 | 158 |
|
203 |
#=====================# |
|
204 |
# Simbology Functions # |
|
205 |
#=====================# |
|
206 |
COLORS = { |
|
207 |
'black': Color.black, |
|
208 |
'blue': Color.blue, |
|
209 |
'cyan': Color.cyan, |
|
210 |
'darkGray': Color.darkGray, |
|
211 |
'gray': Color.gray, |
|
212 |
'green': Color.green, |
|
213 |
'lightGray': Color.lightGray, |
|
214 |
'magenta': Color.magenta, |
|
215 |
'orange': Color.orange, |
|
216 |
'pink': Color.pink, |
|
217 |
'red': Color.red, |
|
218 |
'white': Color.white, |
|
219 |
'yellow': Color.yellow, |
|
220 |
} |
|
221 |
|
|
222 |
def simplePointSymbol(color=None): |
|
223 |
""" |
|
224 |
Returns simple point symbol using parameter color. If no color |
|
225 |
use a ramdom color |
|
226 |
:param color: String color name or Java awt Color |
|
227 |
:return: gvSIG point symbol |
|
228 |
""" |
|
229 |
if isinstance(color, str) and COLORS.has_key(color.lower()): |
|
230 |
color = COLORS.get(color) |
|
231 |
|
|
232 |
if not isinstance(color, Color): |
|
233 |
color = getDefaultColor() |
|
234 |
|
|
235 |
return MapContextLocator.getSymbolManager().createSymbol( |
|
236 |
Geometry.TYPES.POINT, color) |
|
159 |
} |
|
237 | 160 |
|
238 |
def simpleLineSymbol(color=None): |
|
239 |
""" |
|
240 |
Returns simple line symbol using parameter color. If no color use a |
|
241 |
ramdom color |
|
242 |
:param color: String color name or Java awt Color |
|
243 |
:return: gvSIG line symbol |
|
244 |
|
|
245 |
""" |
|
246 |
if isinstance(color, str) and COLORS.has_key(color.lower()): |
|
247 |
color = COLORS.get(color) |
|
161 |
/** |
|
162 |
* Create the path to a resource. |
|
163 |
* |
|
164 |
* This function runs like the os.path.join, but if the first argument is a |
|
165 |
* full path name to a file, it only get the dirname of it. |
|
166 |
* |
|
167 |
* This is usefull to use with the variable __file__ as the first argument |
|
168 |
* to get a path name to a resource relative to the current module. |
|
169 |
* |
|
170 |
* Explample:<br> |
|
171 |
* <code> |
|
172 |
* pathname = getResource(__file__,"data","icon.png") |
|
173 |
* </code> |
|
174 |
* |
|
175 |
* @param parameters parts of path to the resource. |
|
176 |
* @return the path name to the resource. |
|
177 |
*/ |
|
178 |
public String getResource(String... parameters) { |
|
179 |
return null; |
|
180 |
} |
|
248 | 181 |
|
249 |
if not isinstance(color, Color): |
|
250 |
color = getDefaultColor() |
|
251 |
|
|
252 |
return MapContextLocator.getSymbolManager().createSymbol( |
|
253 |
Geometry.TYPES.CURVE, color) |
|
254 |
|
|
255 |
def simplePolygonSymbol(color = None): |
|
256 |
""" |
|
257 |
Returns simple polygon symbol using parameter color. If no color |
|
258 |
use a ramdom color. |
|
259 |
:param color: String color name or Java awt Color |
|
260 |
:return: gvSIG polygon symbol |
|
261 |
""" |
|
262 |
if isinstance(color, str) and COLORS.has_key(color.lower()): |
|
263 |
color = COLORS.get(color) |
|
264 |
|
|
265 |
if not isinstance(color, Color): |
|
266 |
color = getDefaultColor() |
|
267 |
|
|
268 |
return MapContextLocator.getSymbolManager().createSymbol( |
|
269 |
Geometry.TYPES.SURFACE, color) |
|
270 |
|
|
271 |
|
|
272 |
#=========================================# |
|
273 |
# gvSIG Application Preferences Functions # |
|
274 |
#=========================================# |
|
275 |
|
|
276 |
def getDataFolder(): |
|
277 |
""" |
|
278 |
Returns gvSIG data folder. This folder is defined in application |
|
279 |
preferences. If is not defined returns None. |
|
280 |
""" |
|
281 |
return Preferences.userRoot().node("gvsig.foldering").get('DataFolder', None) |
|
282 |
|
|
283 |
def getProjectsFolder(): |
|
284 |
""" |
|
285 |
Returns gvSIG projects folder. This folder is defined in application |
|
286 |
preferences. If is not defined returns None. |
|
287 |
""" |
|
288 |
return Preferences.userRoot().node("gvsig.foldering").get( |
|
289 |
'ProjectsFolder', None) |
|
290 |
|
|
291 |
def getColorFromRGB(r, g, b, a=None): |
|
292 |
""" |
|
293 |
Returns an sRGB color with the specified red, green, blue, and alpha |
|
294 |
(optional) values in the range (0 - 255). |
|
295 |
""" |
|
296 |
if a: |
|
297 |
color = Color(r, g, b, a) |
|
298 |
else: |
|
299 |
color = Color(r, g, b) |
|
300 |
|
|
301 |
return color |
|
302 |
|
|
303 |
def getDefaultColor(c = None): |
|
304 |
"""Returns gvsig default symbol fill color or ramdom color""" |
|
305 |
if MapContextLocator.getSymbolManager().isDefaultSymbolFillColorAleatory(): |
|
306 |
color = Color(random.randint(0-255), |
|
307 |
random.randint(0-255), |
|
308 |
random.randint(0-255) |
|
309 |
) |
|
310 |
else: |
|
311 |
sp = MapContextLocator.getSymbolManager().getSymbolPreferences() |
|
312 |
color = sp.getDefaultSymbolFillColor() |
|
313 |
|
|
314 |
return color |
|
315 |
*/ |
|
182 |
/** |
|
183 |
* Open an existen data store an return it. |
|
184 |
* |
|
185 |
* The type of store depened of store to be opened. It can be: |
|
186 |
* <ul> |
|
187 |
* <li>Shape</li> |
|
188 |
* <li>Dbf</li> |
|
189 |
* <li>DXF</li> |
|
190 |
* <li>DGN</li> |
|
191 |
* <li>DWG</li> |
|
192 |
* <li>JExcel</li> |
|
193 |
* <li>PostgreSQL</li> |
|
194 |
* <li>WFSStore</li> |
|
195 |
* <li>Gdal Store</li> |
|
196 |
* </ul> |
|
197 |
* |
|
198 |
* @param storeType the type of store to open. |
|
199 |
* @param parameters to open the store. |
|
200 |
* @return the opened data store |
|
201 |
*/ |
|
202 |
public DataStore openStore(String storeType, Object... parameters) { |
|
203 |
return null; |
|
204 |
} |
|
205 |
|
|
206 |
/** |
|
207 |
* Create a new projectionobject associated with the passed name of |
|
208 |
* the projection. |
|
209 |
* |
|
210 |
* Usually, the name is the abbreviation of the projection. |
|
211 |
* |
|
212 |
* Is preferable to use this method <code>CRSFactory.getCRS(name)</code> instead. |
|
213 |
* |
|
214 |
* @param name abbreviation of the projection |
|
215 |
* @return the projection object associated with the name |
|
216 |
*/ |
|
217 |
public IProjection getCRS(String name) { |
|
218 |
return null; |
|
219 |
} |
|
220 |
|
|
221 |
/** |
|
222 |
* Return the default data folder of gvSIG. |
|
223 |
* This is configured in the preferences of gvSIG. |
|
224 |
* |
|
225 |
* @return the data folder of gvSIG |
|
226 |
*/ |
|
227 |
public String getDataFolder() { |
|
228 |
return null; |
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* Return the default projects folder of gvSIG. |
|
233 |
* This is configured in the preferences of gvSIG. |
|
234 |
* |
|
235 |
* @return the projects folder of gvSIG. |
|
236 |
*/ |
|
237 |
public String getProjectsFolder() { |
|
238 |
return null; |
|
239 |
} |
|
316 | 240 |
} |
Also available in: Unified diff