On Fri, 27 Jan 2023 05:16:23 -0800 (PST), Elham Peiravian wrote:
> Hi Sandro,
>
> Please disregard my previous message in which I stated that the
> geometry type of my table is unknown. I was mistakenly using the
> wrong
> data.
> I have the correct data now that are legit. And to be 100% sure I did
> the test you recommended and the output was as you mentioned.
>
> My query will be getting implemented into a script for a website, and
> the GeoJSON will be an object. My confusion is whether I am
> referencing the GeoJSON object correctly or not.
>
there are just few details requiring to be fixed in your SQL Query;
let's where and why
a. ST_Intersection(r.geometry, b.geometry)geography
forget GEOGRAPHY in SpatiaLite, it's unsupported; the qualifier
following the SQL function will simply cause a syntax error
b. FROM roads AS r, GeomFromGeoJSON(boundary) AS b
yet another syntax error; you can legitimately create on the fly
a fake table just containing a single value, but not in this way
we are now ready to rewrite he query using the correct syntax:
SELECT Sum(ST_Length(
ST_Intersection(r.geometry, b.geometry) AS TotalLength
FROM roads AS r,
(SELECT GeomFromGeoJson(*BOUNDARY*) AS geometry) AS b
WHERE ST_Intersects(r.geometry, b.geometry = 1;
in which *BOUNDARY* is assumed to be a TEXT constant
containing some valid GeoJSON expression of the Polygon
type.
pay close attention: being a TEXT constant it must be
delimited by a couple of single quotes.
you can easily test for this using this reduced query:
SELECT IsGeometryBLOB(geom), ST_GeometryType(geom), SRID(geom)
FROM (SELECT GeomFromGeoJson(*BOUNDARY*) AS geom);
bye Sandro