expected number but encountered ')'

Topics: Developer Forum
Mar 23, 2008 at 11:55 AM
Hello everybody,

I'm trying to make a simple query:

SELECT oid, fieldA, fieldB
FROM TableName
WHERE (ST.Intersects(ST.GeomFromText('MULTIPOLYGON(((' + CAST(@coords AS nvarchar) + ')))', 4030), ST.Transform(the_geom, 4030)) = 1)

the parameter coords is equal to: -89.18 13.46,-88.84 13.49,-88.98 13.56,-89.11 13.54,-89.18 13.46

I receive the following error:
A .NET framework error occurred during executiuon of user-defined routine or aggragate "GeomFromText":
GisSharpBlog.NetTopologySuite.IO.ParseException: Expected number but encountered ')'

I have tried also to use:
ST.GeomFromText('POLYGON((' + CAST(@coords AS nvarchar) + '))', 4030)

but I receive the same error.

Instead, no problem with POINT(' + CAST(@coords AS nvarchar) + ')

Please help me I can't find a solution!

many many thanks

Mar 23, 2008 at 4:58 PM
Your WKT looks fine (works for me with that string value), so are you sure that (@coords as nvarchar) does evaluate to what you expect it to evaluate as? Could also be an I18N thing... make sure you don't cast your double values using comma as decimal point (often a problem on european computers).

Be aware that your query is very inefficient. You are transforming each row which is expensive. Instead transform your input, and make it a parameter:
DECLARE @poly Geometry --Can't remember the datatype, so please replace 'Geometry' with the correct type name :-)
SET @poly = ST.Transform(ST.GeomFromText('MULTIPOLYGON(((' + CAST(@coords AS nvarchar) + ')))', 4030),xxxx);
SELECT oid, fieldA, fieldB
FROM TableName
WHERE (ST.Intersects(@poly) = 1)

...where 'xxxx' is the SRID of your geometry data.