GeoFormAlchemy - a extension for FormAlchemy that adds support for spatial databases
Project description
GeoFormAlchemy is an extension for FormAlchemy that makes it possible to generate forms for model classes that use the geometry types of GeoAlchemy.
Requirements
Requires FormAlchemy and GeoAlchemy >=0.4.
Installation
Installing using easy_install:
$ easy_install geoformalchemy
Manual installation for development:
Download the source code as archive or clone the GIT repository:
git clone http://github.com/camptocamp/GeoFormAlchemy.git GeoFormAlchemy
Then run the setup:
cd GeoFormAlchemy/GeoFormAlchemy python setup.py develop
Usage in Pylons applications
GeoFormAlchemy includes a Paster Pylons template that builds upon FormAlchemy’s administration interface for Pylons.
If you want to use GeoFormAlchemy in your Pylons application, run paster create with the GeoFormAlchemy template:
$ paster create -t geo_fa your_app [..] Enter admin_controller (Add formalchemy's admin controller) [False]: True Enter template_engine (mako/genshi/jinja2/etc: Template language) ['mako']: mako Enter sqlalchemy (True/False: Include SQLAlchemy 0.5 configuration) [False]: True [..]
Then the GeoFormAlchemy extension has to be activated. Open the file your_app/forms/__init__.py and add the following lines at the end of the file:
# [..] from geoformalchemy.base import GeometryFieldRenderer from geoalchemy import geometry FieldSet.default_renderers[geometry.Geometry] = GeometryFieldRenderer
GeoFormAlchemy is now set up and a map will be displayed in the forms for your geometry fields. Note that you will have to tell FormAlchemy for which model classes it should create forms. To do so import your model classes in the file your_app/model/__init__.py. For more information please refer to the FormAlchemy documentation.
Configuration
Field modifications
The rendering of geometry fields can be customized with additional options. For example the following statement called on the field the_geom of the custom FieldSet changes the background map (inside the file your_app/forms/__init__.py):
Place = FieldSet(model.places.Place) Place.the_geom.set(options=[ ('map_srid', 900913), ('base_layer', 'new OpenLayers.Layer.OSM("OSM")') ])
The following options are available in GeoFormAlchemy:
- default_lat and default_lon
If the geometry is None or when creating a new geometry, the map is centered at (default_lon, default_lat). Otherwise the map is centered at the centroid of the geometry.
- zoom
The zoom-level on start-up.
- map_width and map_height
The size of the DIV container in which the map is displayed.
- base_layer
The OpenLayers layer which will be used as background map, for example:
('base_layer', 'new OpenLayers.Layer.OSM("OSM")')
- map_srid
If the map uses a different CRS than the geometries, the geometries will be reprojected to this CRS. For example:
('map_srid', 900913)
- openlayers_lib
The path to the OpenLayers JavaScript library, for example if OpenLayers.js is located at your_app/public/js/lib/OpenLayers.js use the following path:
('openlayers_lib', '/js/lib/OpenLayers.js')
- show_map (default: True)
If show_map is set to False, the geometry will be displayed as WKT string inside a text input field.
Template files
If you want to change the look of your forms, you can modify the template files used by FormAlchemy and GeoFormAlchemy. The template files are located in the folder your_app/templates/forms.
GeoFormAlchemy uses the template files map_js.mako and map.mako. In map.mako you can set most of the options that you can also use as field modification. But unlike to field modifications, the options set in the template file are used for the geometry fields of all models, whereas the options set as field modification are only used for the field they were set on.
<% # default configuration options that will be used when # no field options were set options = {} options['default_lon'] = 10 options['default_lat'] = 45 options['zoom'] = 4 options['map_width'] = 512 options['map_height'] = 256 options['base_layer'] = 'new OpenLayers.Layer.WMS("WMS", "http://labs.metacarta.com/wms/vmap0", {layers: "basic"})' options['openlayers_lib'] = 'http://openlayers.org/api/OpenLayers.js' %>
If you want to customize the OpenLayers map, for example to add a further OpenLayers control or to add a second background layer, modify the file map_js.mako.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file GeoFormAlchemy-0.3.tar.gz
.
File metadata
- Download URL: GeoFormAlchemy-0.3.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9084a6980f436974db8bdb63fd03b94d832ad706b8755ae8ed55117c2b785655 |
|
MD5 | 9817d0e53ee07e3ce7cd110b5da5219d |
|
BLAKE2b-256 | 3ff7fffb89342bd257e357f95b1ca006018974e47c895bc97d99a69fca4cda78 |