Thanks, Massimo - I believe the Field('loc', 'geometry()') or Field('loc',
'geography()') variant should be correct - that's what the web2py book
suggests
<http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#PostGIS--SpatiaLite--and-MS-Geo--experimental->,
and that's what other users are doing
<https://groups.google.com/d/msg/web2py/feh1ksfdkGk/YoY9jUTXDi4J>. For
spatialite, Field('loc', 'geometry()') worked for me (at least as far as
creating the field goes), and if I use Field('loc', 'geometry'), I get this
error message:
3. Exception in 'table definition': need more than 1 value to unpack
Traceback:
Looking at "class SpatiaLiteAdapter(SQLiteAdapter)" in pydal, I see these
lines, with no corresponding types.update() for 'GEOGRAPHY':
types = copy.copy(BaseAdapter.types)
types.update(geometry='GEOMETRY')
Going a bit further, the lines pertaining to geography are commented out:
def represent(self, obj, fieldtype):
field_is_type = fieldtype.startswith
if field_is_type('geo'):
srid = 4326 # Spatialite default srid for geometry
geotype, parms = fieldtype[:-1].split('(')
parms = parms.split(',')
if len(parms) >= 2:
schema, srid = parms[:2]
# if field_is_type('geometry'):
value = "ST_GeomFromText('%s',%s)" %(obj, srid)
# elif field_is_type('geography'):
# value = "ST_GeogFromText('SRID=%s;%s')" %(srid, obj)
# else:
# raise SyntaxError, 'Invalid field type %s' %fieldtype
return value
return BaseAdapter.represent(self, obj, fieldtype)
I haven't delved into it too deeply, and don't know if the stuff pertaining
to "GEOGRAPHY" is handled in some other way for spatialite, or but perhaps
the above explains why there doesn't seem to be a geography type. For
comparison's sake, the postgres adapter has the following lines:
if field_is_type('geometry'):
value = "ST_GeomFromText('%s',%s)" %(obj, srid)
elif field_is_type('geography'):
value = "ST_GeogFromText('SRID=%s;%s')" %(srid, obj)
Either way, I could do without the geography type, but if geometry is the
only option, I'd be curious to know how to find rows within a certain
number of meters of a location, using the geometry type.
On Wednesday, November 11, 2015 at 10:40:44 AM UTC-5, Massimo Di Pierro
wrote:
>
> I think it is
> Field('loc','geometry')
> and
> Field('loc','geography')
>
> without the ().
>
> On Wednesday, 11 November 2015 08:51:48 UTC-6, Boa wrote:
>>
>> I'd like to find all table entries within x meters of a certain location.
>> The DAL object in question uses the spatialite adapter (my system's
>> spatialite library is the most recent version), and the field of interest
>> is of type 'geometry':
>>
>> db = DAL('spatialite://...')
>> db.define_table('point', Field('name'), Field('loc','geometry()'))
>>
>> Massimo suggested the following
>> <https://groups.google.com/d/msg/web2py/ahO2ydF7yK0/yPH1QC-h3IYJ> as a
>> method of finding rows within distance:
>>
>> query = db.point.loc.st_distance(geoPoint(37.7833, 122.4167)) < 10
>> rows = db(query).select(db.point.name)
>>
>> However, as I understand, the above query does the following
>> <http://www.postgis.org/docs/ST_Distance.html>:
>>
>> For geometry type Returns the 2-dimensional cartesian minimum distance
>>> (based on spatial ref) between two geometries in projected units. For
>>> geography type defaults to return spheroidal minimum distance between two
>>> geographies in meters.
>>>
>>
>> If I change the 'loc' field's type to 'geography()', I get the following
>> exception:
>>
>> 3. Exception in 'point definition': Field: unknown field type: geography
>> () for loc
>>
>> I've also tried tinkering with the st_within() method
>> <https://groups.google.com/forum/#!searchin/web2py/st_within/web2py/mHHeVNfYV6g/rev9zRKBdXcJ>,
>>
>> but doing so generates this error message:
>>
>> <type 'exceptions.AttributeError'> 'SpatiaLiteAdapter' object has no
>> attribute 'ST_DWITHIN'
>>
>> When using the spatialite adapter, what is the recommended way to find
>> records within some distance, measured in meters?
>>
>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.