geo/db/mysql_spatial.inc, line 26
- Versions
- 6
geo_mysql_spatial_add_field(&$ret, $table, $field, $spec)
Adds a geometry column to the specified table.
Parameters
$table The name of the table to which to add the column. Do not include braces ({}).
$field_name The name of the field to use.
$type The OpenGIS type of the column. Valid types are: POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION
$srid The Spatial Reference ID of this column's projection. The most commonly used SRID is GEO_SRID_DEFAULT, which corresponds to unprojected lat-long in WGS84.
Return value
boolean Success or failure
Code
<?php
function geo_mysql_spatial_add_field(&$ret, $table, $field, $spec) {
// NOTE for now, all geometries are 2d. deal with it
$ret[] = db_query("ALTER TABLE {%s} ADD %s %s NOT NULL", $table, $field, $spec['type']);
db_query("CREATE SPATIAL INDEX {$table}_${field}_idx ON {". $table ."} ($field)");
// @@@ Error handling
return true;
}
?> 