Statistics
| Revision:

gvsig-scripting / 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 @ 735

History | View | Annotate | Download (7.91 KB)

1
package scripting;
2

    
3
import org.gvsig.fmap.dal.feature.FeatureType;
4
import org.gvsig.fmap.mapcontext.layers.FLayer;
5

    
6
/**
7
 * Representa al modulo python "gvsig".
8
 * 
9
 * Es el modulo base que nos facilita el acceso a todos
10
 * los componentes de gvSIG.
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>
14
 *
15
 * 
16
 */
17
public class gvsig {
18

    
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
  }
54

    
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
  }
90

    
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
  
133

    
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
  )
155

156
def createTable(schema, servertype, tableType=None, **parameters):
157
  """Creates a new Table document"""
158
  if tableType == None:
159
    tableType = servertype
160
    servertype = "FilesystemExplorer"
161

162
  try:
163
    application = ApplicationLocator.getManager()
164
    datamanager =  application.getDataManager()
165
    
166
    server_parameters = datamanager.createServerExplorerParameters(servertype)
167
    copyToDynObject(parameters, server_parameters)
168

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)
176

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
  )
201

202

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)
237

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)
248

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
*/
316
}