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 / javadocs / scripting / gvsig.java @ 462

History | View | Annotate | Download (7.49 KB)

1
package scripting;
2

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

    
6
public class gvsig {
7

    
8
  /**
9
   * Returns a new and empty attributes definition. 
10
   *
11
   * @deprecated use createFeatureType instead
12
   */
13
  public static FeatureType createSchema() {
14
    return null;
15
  }
16
  
17
  /**
18
   * Returns a new and empty attributes definition based in an 
19
   * existing schema.
20
   *
21
   * @deprecated use createFeatureType instead
22
   */
23
  public static FeatureType createSchema(FeatureType schema) {
24
    return null;
25
  }
26
  
27
  /**
28
   * Returns a new and empty attributes definition. 
29
   *
30
   */
31
  public static FeatureType createFeatureType() {
32
    return null;
33
  }
34
  
35
  /**
36
   * Returns a new and empty attributes definition based in an 
37
   * existing schema.
38
   *
39
   */
40
  public static FeatureType createFeatureType(FeatureType schema) {
41
    return null;
42
  }
43

    
44
  /**
45
    * Create a new layer with the specified parameters.
46
    *
47
    * The paramaters "..." are used to connect to the server type and
48
    * create the layer.
49
    *
50
    * Valid values of server type are:
51
    * - FilesystemExplorer
52
    * - TODO
53
    *
54
    * Valid values of layer type are:
55
    * - Shape
56
    * - TODO
57
    *
58
    * Excamples of use:
59
    * TODO
60
    *
61
    * @param schema the schema to use to create la layer.
62
    * @param serverType The server type (filesystem, BBDD, ...)
63
    * @param layerType The layer type to create (Shape, ...)
64
    * 
65
    */
66
  public static FLayer creaetLayer(FeatureType schema, String serverType, String layerType, ...) {
67
    return null;
68
  }
69
  
70
  /**
71
    * Create a new layer with the specified parameters.
72
    *
73
    * Use as default serverType the "FilesystemExplorer".
74
    *
75
    */
76
  public static FLayer creaetLayer(FeatureType schema, String layerType, ...) {
77
    return null;
78
  }
79

    
80
  /**
81
    * Load an existing shape file in the current view.
82
    *
83
    * @param path path to the shape file to load
84
    * @param projection to use to load the shape file
85
    *
86
    */
87
  public static FLayer loadShapeFile(String path, String projection) {
88
    return null;
89
  }
90
  
91
  /**
92
    * Load an existing shape file in the current view.
93
    *
94
    * Use as default projection "CRS:84"
95
    *
96
    * @param path path to the shape file to load
97
    * 
98
    */
99
  public static FLayer loadShapeFile(String path) {
100
    return null;
101
  }
102
  
103
  /**
104
    * Load an existing layer and return it.
105
    *
106
    * Valid values of layer type are:
107
    * - Shape
108
    * - TODO
109
    *
110
    * @param layerType 
111
    * 
112
    */
113
  public static FLayer loadLayer(String layerType, ...) {
114
    return null;
115
  }
116
  
117
  
118

    
119
  
120
  def createShape(definition, filename, geometryType, CRS="CRS:84"):
121
  """
122
  Return new shape layer 
123
  :param definition: layer data definition
124
  :type definition: Schema
125
  :param filename: absolute path for shape files. 
126
  :type filename: string
127
  :param geometryType: geometry type for shape
128
  :type geometryType: string
129
  :return: new shape layer
130
  :rtype: Layer
131
  """
132
  return createLayer(
133
    definition, 
134
    "FilesystemExplorer", 
135
    "Shape", 
136
    shpFile=filename, 
137
    CRS=CRS,
138
    geometryType = geometryType
139
  )
140

    
141
def createTable(schema, servertype, tableType=None, **parameters):
142
  """Creates a new Table document"""
143
  if tableType == None:
144
    tableType = servertype
145
    servertype = "FilesystemExplorer"
146

    
147
  try:
148
    application = ApplicationLocator.getManager()
149
    datamanager =  application.getDataManager()
150
    
151
    server_parameters = datamanager.createServerExplorerParameters(servertype)
152
    copyToDynObject(parameters, server_parameters)
153

    
154
    server = datamanager.openServerExplorer(servertype, server_parameters)
155
    
156
    store_parameters = server.getAddParameters(tableType)
157
    copyToDynObject(parameters, store_parameters)
158
    store_parameters.setDefaultFeatureType(schema())
159
    
160
    server.add(tableType, store_parameters, True)
161

    
162
    store = datamanager.openStore(tableType, store_parameters)
163
    
164
    return store
165
  
166
  except Throwable, ex:
167
    raise RuntimeException("Can't create table, "+ str(ex))
168
  
169
def createDBF(definition, DbfFile, CRS="CRS:84"):
170
  """
171
  Creates a new dbf document 
172
  :param definition: layer data definition
173
  :type definition: Schema
174
  :param DbfFile: absolute path for shape files. 
175
  :type DbfFile: string
176
  :return: new dbf
177
  :rtype: Table    
178
  """
179
  return createTable(
180
    definition, 
181
    "FilesystemExplorer", 
182
    "DBF", 
183
    DbfFile=DbfFile, 
184
    CRS=CRS,
185
  )
186

    
187

    
188
#=====================#
189
# Simbology Functions #
190
#=====================#  
191
COLORS = {
192
    'black': Color.black,
193
    'blue': Color.blue,
194
    'cyan': Color.cyan,
195
    'darkGray': Color.darkGray,
196
    'gray': Color.gray,
197
    'green': Color.green,
198
    'lightGray': Color.lightGray,
199
    'magenta': Color.magenta,
200
    'orange': Color.orange,
201
    'pink': Color.pink,
202
    'red': Color.red,
203
    'white': Color.white,
204
    'yellow': Color.yellow,
205
}
206
  
207
def simplePointSymbol(color=None):
208
  """
209
  Returns simple point symbol using parameter color. If no color 
210
  use a ramdom color
211
  :param color: String color name or Java awt Color
212
  :return: gvSIG point symbol
213
  """
214
  if isinstance(color, str) and COLORS.has_key(color.lower()):
215
    color = COLORS.get(color)
216
    
217
  if not isinstance(color, Color):
218
      color = getDefaultColor()
219
      
220
  return MapContextLocator.getSymbolManager().createSymbol(
221
        Geometry.TYPES.POINT, color)
222

    
223
def simpleLineSymbol(color=None):
224
  """
225
  Returns simple line symbol using parameter color. If no color use a 
226
  ramdom color  
227
  :param color: String color name or Java awt Color
228
  :return: gvSIG line symbol
229
  
230
  """
231
  if isinstance(color, str) and COLORS.has_key(color.lower()):
232
    color = COLORS.get(color)
233

    
234
  if not isinstance(color, Color):
235
      color = getDefaultColor()
236
      
237
  return MapContextLocator.getSymbolManager().createSymbol(
238
        Geometry.TYPES.CURVE, color)
239

    
240
def simplePolygonSymbol(color = None):
241
  """
242
  Returns simple polygon symbol using parameter color. If no color 
243
  use a ramdom color.  
244
  :param color: String color name or Java awt Color
245
  :return: gvSIG polygon symbol
246
  """
247
  if isinstance(color, str) and COLORS.has_key(color.lower()):
248
    color = COLORS.get(color)
249

    
250
  if not isinstance(color, Color):
251
      color = getDefaultColor()
252
  
253
  return MapContextLocator.getSymbolManager().createSymbol(
254
        Geometry.TYPES.SURFACE, color)
255
  
256

    
257
#=========================================#
258
# gvSIG Application Preferences Functions #
259
#=========================================#  
260

    
261
def getDataFolder():
262
  """
263
  Returns gvSIG data folder. This folder is defined in application 
264
  preferences. If is not defined returns None.
265
  """
266
  return Preferences.userRoot().node("gvsig.foldering").get('DataFolder', None)
267
  
268
def getProjectsFolder():
269
  """
270
  Returns gvSIG projects folder. This folder is defined in application 
271
  preferences. If is not defined returns None.
272
  """
273
  return Preferences.userRoot().node("gvsig.foldering").get(
274
        'ProjectsFolder', None)
275

    
276
def getColorFromRGB(r, g, b, a=None):
277
  """
278
  Returns an sRGB color with the specified red, green, blue, and alpha 
279
  (optional) values in the range (0 - 255).
280
  """
281
  if a:
282
    color = Color(r, g, b, a)
283
  else:
284
    color = Color(r, g, b)
285
  
286
  return color
287
  
288
def getDefaultColor(c = None):
289
  """Returns gvsig default symbol fill color or ramdom color"""
290
  if MapContextLocator.getSymbolManager().isDefaultSymbolFillColorAleatory():
291
    color = Color(random.randint(0-255), 
292
                random.randint(0-255), 
293
                random.randint(0-255)
294
            )
295
  else:
296
    sp = MapContextLocator.getSymbolManager().getSymbolPreferences()
297
    color = sp.getDefaultSymbolFillColor()    
298

    
299
  return color  
300

    
301
}