Changeset 461 for ZCO/branches/pg-user-store
- Timestamp:
- 01/12/06 02:04:07 (5 years ago)
- Location:
- ZCO/branches/pg-user-store
- Files:
-
- 3 modified
-
DataStore.py (modified) (12 diffs)
-
www/add_datastore.html (modified) (2 diffs)
-
www/edit_datastore.html (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ZCO/branches/pg-user-store/DataStore.py
r425 r461 26 26 from Acquisition import Implicit 27 27 from OFS import SimpleItem, PropertyManager 28 from OFS.Folder import Folder 28 29 from Products.PageTemplates.PageTemplateFile import PageTemplateFile 29 30 from AccessControl.Role import RoleManager … … 45 46 46 47 class DataStore(Persistent, Implicit, PropertyManager.PropertyManager, 47 RoleManager, SimpleItem.Item):48 RoleManager, Folder): 48 49 49 50 """GIS data on disk or (soon) in an RDBMS. … … 77 78 ) + PropertyManager.PropertyManager.manage_options \ 78 79 + RoleManager.manage_options \ 79 + SimpleItem.Item.manage_options80 + (Folder.manage_options[0],) 80 81 81 82 def _port_srs(self, srs): … … 135 136 def __init__(self, path): 136 137 self.path = path 138 self.datastoretype = 'DiskFeatureStore' 137 139 138 140 def typenames(self): … … 192 194 def __init__(self, path): 193 195 self.path = path 196 self.datastoretype = 'DiskRasterStore' 194 197 195 198 def datastore(self): … … 216 219 def __init__(self, connection): 217 220 self.connection = connection 221 self.datastoretype = 'PGFeatureStore' 218 222 219 223 def datastore(self): … … 260 264 261 265 266 class PGUserFeatureStore(DataStore): 267 268 """PostGIS feature store 269 270 Attributes 271 ---------- 272 connection : string 273 Database connection parameters such as 'host=localhost dbname=foo' 274 """ 275 276 def __init__(self, connection, typename, datatype, geom, srid, gid, 277 sql_select, sql_from, sql_where='', sql_order=''): 278 self.connection = connection 279 self.typename = typename 280 self.datatype = datatype 281 self.geom = geom 282 self.datatype = datatype 283 self.gid = gid 284 self.srid = srid 285 self.sql_select = sql_select 286 self.sql_from = sql_from 287 self.sql_where = sql_where 288 self.sql_order = sql_order 289 self.datastoretype = 'PGUserFeatureStore' 290 291 def datastore(self): 292 """Return an instance of PCL's PgFeatureStore""" 293 wherestring = self.sql_where 294 if hasattr(self, 'sqlwhere'): 295 if wherestring: 296 wherestring = '(' + wherestring + ') AND ' 297 wherestring = wherestring + '(' + self.sqlwhere() + ')' 298 return postgis.PGUserFeatureStore(self.typename, self.gid, self.srid, self.datatype, self.geom, 299 self.sql_select, self.sql_from, wherestring, self.sql_order, 300 self.connection) 301 302 def typenames(self): 303 """Return a list of feature type names""" 304 return self.datastore().typenames() 305 306 def manage_edit(self, connection=None, datatype=None, geom=None, srid=None, 307 gid=None, sql_select=None, sql_from=None, sql_where=None, sql_order=None, 308 REQUEST=None): 309 """Web front end to modify_attributes""" 310 self.modify_attributes(connection=connection) 311 self.modify_attributes(datatype=datatype) 312 self.modify_attributes(geom=geom) 313 self.modify_attributes(srid=srid) 314 self.modify_attributes(gid=gid) 315 self.modify_attributes(sql_select=sql_select) 316 self.modify_attributes(sql_from=sql_from) 317 self.modify_attributes(sql_where=sql_where) 318 self.modify_attributes(sql_order=sql_order) 319 return self.manage_editForm(self, REQUEST, update_menu=1) 320 321 def search(self, typename, filter=str(True)): 322 """Callable like a Zope catalog, returns an iterator over features""" 323 f_string = filter 324 query = Query(filter=PythonFilter(f_string)) 325 results = [] 326 source = self.datastore().source(typename) 327 schema = source.schema() 328 329 class F(Record, Implicit): 330 __record_schema__ = {'g': 0} 331 __record_schema__.update( 332 dict([(schema[i][0], i+1) for i in range(len(schema))]) 333 ) 334 __record_schema__['data_record_id_']=len(schema)+1 335 __record_schema__['data_record_score_']=len(schema)+2 336 __record_schema__['data_record_normalized_score_']=len(schema)+3 337 338 i = 0 339 for f, a in source.iterfeatures(query): 340 rec = F((f,) + tuple(a) + (i, 0, 0)) 341 i += 1 342 results.append(rec) 343 344 return results 345 346 def __call__(self, typename, filter): 347 """Callable like a Zope catalog, returns an iterator over features""" 348 return self.search(typename, filter) 349 262 350 263 351 class WMSRasterStore(DataStore): … … 279 367 self.version = version 280 368 self.incoming = incoming 369 self.datastoretype = 'WMSRasterStore' 281 370 282 371 def datastore(self): … … 308 397 self.version = version 309 398 self.incoming = None 399 self.datastoretype = 'WFSFeatureStore' 310 400 311 401 def datastore(self): … … 328 418 def manage_addDataStore(dispatcher, id, type, title=None, abstract=None, 329 419 path=None, connection=None, url=None, version=None, 420 datatype=None, geom=None, srid=None, gid=None, 421 sql_select=None, sql_from=None, sql_where=None, 422 sql_order=None, 330 423 incoming=None, REQUEST=None): 331 424 """Add a new data store to a folder""" … … 341 434 elif type == 'POSTGIS': 342 435 ob = PGFeatureStore(connection) 436 elif type == 'POSTGIS2': 437 ob = PGUserFeatureStore(typename=id, datatype=datatype, 438 geom=geom, srid=srid, gid=gid, 439 sql_select=sql_select, sql_from=sql_from, sql_where=sql_where, sql_order=sql_order, 440 connection=connection) 343 441 else: 344 442 raise Exception, "invalid datastore type: %s" % (type) … … 362 460 Globals.InitializeClass(DataStore) 363 461 462 -
ZCO/branches/pg-user-store/www/add_datastore.html
r209 r461 7 7 8 8 <span tal:define="datatypes python:{'SHAPEFILE': 'Local Shapefile Features', 9 'POSTGIS2': 'PostGIS Features (user-defined)', 9 10 'POSTGIS': 'PostGIS Features', 10 11 'RASTER': 'Local GDAL Raster', … … 191 192 </span> 192 193 194 195 <!-- 196 User-defined PostGIS store, distinguished by a set of properties 197 --> 198 <span tal:condition="python:datatype=='POSTGIS2'"> 199 <tr> 200 <td align="left" valign="top"> 201 <div class="form-label"> 202 connection 203 </div> 204 </td> 205 <td align="left" valign="top"> 206 <input type="text" name="connection" size="73"/> 207 </td> 208 </tr> 209 <tr> 210 <td align="left" valign="top"> 211 <div class="form-label"> 212 datatype 213 </div> 214 </td> 215 <td align="left" valign="top"> 216 <select name="datatype" size="1"> 217 <option value="Point">Point</option> 218 <option value="LineString">LineString</option> 219 <option value="Polygon">Polygon</option> 220 <option value="MultiPolygon">MultiPolygon</option> 221 </select> 222 </td> 223 </tr> 224 <tr> 225 <td align="left" valign="top"> 226 <div class="form-label"> 227 GID (unique identifier) 228 </div> 229 </td> 230 <td align="left" valign="top"> 231 <input type="text" name="gid" size="40"/> 232 </td> 233 </tr> 234 <tr> 235 <td align="left" valign="top"> 236 <div class="form-label"> 237 geometry column 238 </div> 239 </td> 240 <td align="left" valign="top"> 241 <input type="text" name="geom" size="73"/> 242 </td> 243 </tr> 244 <tr> 245 <td align="left" valign="top"> 246 <div class="form-label"> 247 SRID 248 </div> 249 </td> 250 <td align="left" valign="top"> 251 <input type="text" name="srid" size="73"/> 252 </td> 253 </tr> 254 <tr> 255 <td colspan="2"> 256 <div class="form-help"> 257 SQL generation 258 </div> 259 </td> 260 </tr> 261 <tr> 262 <td align="left" valign="top"> 263 <div class="form-label"> 264 Attribute Fields 265 </div> 266 </td> 267 <td align="left" valign="top"> 268 <textarea name="sql_select" rows="5" cols="50"></textarea> 269 </td> 270 </tr> 271 <tr> 272 <td align="left" valign="top"> 273 <div class="form-label"> 274 FROM clause 275 </div> 276 </td> 277 <td align="left" valign="top"> 278 <textarea name="sql_from" rows="5" cols="50"></textarea> 279 </td> 280 </tr> 281 <tr> 282 <td align="left" valign="top"> 283 <div class="form-label"> 284 WHERE clause 285 </div> 286 </td> 287 <td align="left" valign="top"> 288 <textarea name="sql_where" rows="5" cols="50"></textarea> 289 </td> 290 </tr> 291 <tr> 292 <td align="left" valign="top"> 293 <div class="form-label"> 294 ORDER BY clause 295 </div> 296 </td> 297 <td align="left" valign="top"> 298 <textarea name="sql_order" rows="5" cols="50"></textarea> 299 </td> 300 </tr> 301 302 </span> 303 193 304 <tr> 194 305 <td align="left" valign="top"></td> -
ZCO/branches/pg-user-store/www/edit_datastore.html
r422 r461 3 3 4 4 <p class="form-help"> 5 Edit ZCO Data Store. 5 Edit ZCO Data Store.... 6 6 </p> 7 7 … … 69 69 PostGIS store, distinguished by a dsn property 70 70 --> 71 <span tal:condition=" exists:here/connection">71 <span tal:condition="python:context.datastoretype=='PGFeatureStore'"> 72 72 <p class="form-help"> 73 73 For example: host=localhost dbname=zcodb user=zcouser … … 86 86 </td> 87 87 </tr> 88 </table> 89 </span> 90 91 <!-- 92 PostGIS user feature store, distinguished by a dsn property 93 --> 94 <span tal:condition="python:context.datastoretype=='PGUserFeatureStore'"> 95 96 <table cellspacing="0" cellpadding="2" border="0"> 97 98 <tr> 99 <td align="left" valign="top"> 100 <div class="form-label"> 101 connection 102 </div> 103 </td> 104 <td align="left" valign="top"> 105 <input type="text" name="connection" size="73" 106 tal:attributes="value here/connection | nothing"/> 107 </td> 108 <td align="left" valign="top"> 109 <div class="form-help"> 110 For example 'dbname=mydb user=myself host=myhost' 111 </div> 112 </td> 113 </tr> 114 115 <tr> 116 <td align="left" valign="top"> 117 <div class="form-label"> 118 datatype 119 </div> 120 </td> 121 <td align="left" valign="top"> 122 <select name="datatype" size="1"> 123 <option value="Point" tal:attributes="selected python:test(context.datatype=='Point','selected','')">Point</option> 124 <option value="LineString" tal:attributes="selected python:test(context.datatype=='LineString','selected','')">LineString</option> 125 <option value="Polygon" tal:attributes="selected python:test(context.datatype=='Polygon','selected','')">Polygon</option> 126 <option value="MultiPolygon" tal:attributes="selected python:test(context.datatype=='MultiPolygon','selected','')">MultiPolygon</option> 127 </select> 128 </td> 129 <td align="left" valign="top"> 130 <div class="form-help"> 131 132 </div> 133 </td> 134 </tr> 135 136 <tr> 137 <td align="left" valign="top"> 138 <div class="form-label"> 139 GID (unique identifier) 140 </div> 141 </td> 142 <td align="left" valign="top"> 143 <input type="text" name="gid" size="40" 144 tal:attributes="value here/gid | nothing"/> 145 </td> 146 <td align="left" valign="top"> 147 <div class="form-help"> 148 149 </div> 150 </td> 151 </tr> 152 153 <tr> 154 <td align="left" valign="top"> 155 <div class="form-label"> 156 geometry column 157 </div> 158 </td> 159 <td align="left" valign="top"> 160 <input type="text" name="geom" size="73" 161 tal:attributes="value here/geom | nothing"/> 162 </td> 163 <td align="left" valign="top"> 164 <div class="form-help"> 165 166 </div> 167 </td> 168 </tr> 169 170 <tr> 171 <td align="left" valign="top"> 172 <div class="form-label"> 173 SRID 174 </div> 175 </td> 176 <td align="left" valign="top"> 177 <input type="text" name="srid" size="73" 178 tal:attributes="value here/srid | nothing"/> 179 </td> 180 <td align="left" valign="top"> 181 <div class="form-help"> 182 183 </div> 184 </td> 185 </tr> 186 187 <tr> 188 <td colspan="3"> 189 <div class="form-help"> 190 SQL generation 191 </div> 192 </td> 193 </tr> 194 195 <tr> 196 <td align="left" valign="top"> 197 <div class="form-label"> 198 Attribute Fields 199 </div> 200 </td> 201 <td align="left" valign="top"> 202 <textarea name="sql_select" rows="5" cols="50" 203 tal:content="here/sql_select|Nothing"></textarea> 204 </td> 205 <td align="left" valign="top"> 206 <div class="form-help"> 207 208 </div> 209 </td> 210 </tr> 211 212 <tr> 213 <td align="left" valign="top"> 214 <div class="form-label"> 215 FROM clause 216 </div> 217 </td> 218 <td align="left" valign="top"> 219 <textarea name="sql_from" rows="5" cols="50" 220 tal:content="here/sql_from|Nothing"></textarea> 221 </td> 222 <td align="left" valign="top"> 223 <div class="form-help"> 224 225 </div> 226 </td> 227 </tr> 228 229 <tr> 230 <td align="left" valign="top"> 231 <div class="form-label"> 232 WHERE clause 233 </div> 234 </td> 235 <td align="left" valign="top"> 236 <textarea name="sql_where" rows="5" cols="50" 237 tal:content="here/sql_where|Nothing"></textarea> 238 </td> 239 <td align="left" valign="top"> 240 <div class="form-help"> 241 242 </div> 243 </td> 244 </tr> 245 246 <tr> 247 <td align="left" valign="top"> 248 <div class="form-label"> 249 ORDER BY clause 250 </div> 251 </td> 252 <td align="left" valign="top"> 253 <textarea name="sql_order" rows="5" cols="50" 254 tal:content="here/sql_order|Nothing"></textarea> 255 </td> 256 <td align="left" valign="top"> 257 <div class="form-help"> 258 259 </div> 260 </td> 261 </tr> 262 88 263 </table> 89 264 </span> … … 103 278 </table> 104 279 </form> 105 280 <!-- 106 281 <div tal:define="store here/datastore" tal:on-error="structure string:<div style='background:#ff0000;color:#000000'>Data store is improperly configured: ${error/value}"/> 107 282 --> 108 283 <tal:zmi_footer replace="structure here/manage_page_footer"/>
