[postgis-users] getting a square/rectangle arround a point

800 views
Skip to first unread message

Daniel Grum

unread,
Aug 18, 2009, 10:16:06 AM8/18/09
to PostGIS Mailing-List
Dear Mailing-List,

I want to create a square/rectangle around a point-->via box2d(geometry)
or buffer(geometry, double precision) for example.

If I have this rectangle I want to intersect this with another
polygon--> saved in the (geodata) table: wald_by column: the_geom, to
get information about the area the the "lumberjack" can dig.
The point in the middle of the rectangle = the point that is saved in a
table in my database in the table: holzfaeller in the column the_geom!

Is this possible to solve?
Do I have to save this calculated square/rectangle in an extra/own table?

Thanks for every help.

Daniel
_______________________________________________
postgis-users mailing list
postgi...@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

Pavel Iacovlev

unread,
Aug 18, 2009, 12:43:08 PM8/18/09
to danie...@unibw.de, PostGIS Users Discussion
st_intersection(st_envelope(st_buffer(t1.the_geom, $radius)), t2. the_geom)

2009/8/18 Daniel Grum <danie...@unibw.de>:

--
http://iap.md, The future is open

Daniel Grum

unread,
Aug 20, 2009, 7:35:27 AM8/20/09
to PostGIS Mailing-List
Daniel Grum schrieb:
> Pavel Iacovlev schrieb:

>> st_intersection(st_envelope(st_buffer(t1.the_geom, $radius)), t2.
>> the_geom)
>>
>> 2009/8/18 Daniel Grum <danie...@unibw.de>:
>>
>>> Dear Mailing-List,
>>>
>>> I want to create a square/rectangle around a point-->via
>>> box2d(geometry) or
>>> buffer(geometry, double precision) for example.
>>>
>>> If I have this rectangle I want to intersect this with another
>>> polygon-->
>>> saved in the (geodata) table: wald_by column: the_geom, to get
>>> information
>>> about the area the the "lumberjack" can dig.
>>> The point in the middle of the rectangle = the point that is saved in a
>>> table in my database in the table: holzfaeller in the column the_geom!
>>>
>>> Is this possible to solve?
>>> Do I have to save this calculated square/rectangle in an extra/own
>>> table?
>>>
>>> Thanks for every help.
>>>
>>> Daniel
>>> _______________________________________________
>>> postgis-users mailing list
>>> postgi...@postgis.refractions.net
>>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>>>
>>>
>>
>>
>>
>>
> I try solve the problem with your message:
>
> SELECT st_intersection(st_envelope(st_buffer('holzfaeller.the_geom',
> 10, 'quad_segs=8')),wald_by.the_geom);
>
>
> I get this error message:
>
> FEHLER: parse error - invalid geometry
>
> ********** Fehler **********
>
> FEHLER: parse error - invalid geometry
> SQL Status:XX000
>
> What do you think is the problem in this case.
> Is there a understaning mistake in my SQL order.
>
> Thanks,
> Daniel
>
I thing I solved the problem:

SELECT st_intersection(st_envelope(st_buffer(a.the_geom,1)),b.the_geom)
FROM public.holzfaeller a, public.wald_by b
(WHERE a.gid=3); //not necessary

Thank You Pavel for the fast answer!

Daniel Grum

unread,
Aug 20, 2009, 10:29:07 AM8/20/09
to PostGIS Mailing-List, Pavel Iacovlev
Daniel Grum schrieb:
The problem now:

this order calculates a lot of points and the intersection with the
layer "wald_by" can't be solved because the geo data typ is:
GEOMETRYCOLLECTION.

I tried to generate a rectangle with ST_GeomGromText instaead of the
st_buffer that generates a circle:

ST_GeomFromText('POLYGON((st_x(a.the_geom)-2.0
st_y(a.the_geom)+2.0,st_x(a.the_geom)+2.0
st_y(a.the_geom)+2.0,st_x(a.the_geom)+2.0
st_y(a.the_geom)-2.0,st_x(a.the_geom)-2.0
st_y(a.the_geom)-2.0,st_x(a.the_geom)-2.0 st_y(a.the_geom)+2.0))')

PostgreSQL don't alerted me with a mistake, but if I would look for the
generated data, PostgreSQL isn't able to do this and said "Bricht ab".

What can be the reason for this?

Thanks

Kevin Neufeld

unread,
Aug 20, 2009, 11:48:41 AM8/20/09
to danie...@unibw.de, PostGIS Users Discussion
Unless I misunderstand what you are after, why don't you simply expand the bounding box of the point by your required
amount?

ie.
SELECT
ST_AsText(geom),
ST_AsText(ST_Expand(geom, 2))
FROM (SELECT 'POINT(5 5)'::geometry AS geom) AS a;

st_astext | st_astext
------------+--------------------------------
POINT(5 5) | POLYGON((3 3,3 7,7 7,7 3,3 3))
(1 row)


-- Or create a rectangle from a point
SELECT
ST_AsText(geom),
ST_AsText(
ST_Envelope(ST_MakeLine(
ST_MakePoint(ST_X(geom) - 3, ST_Y(geom) - 2),
ST_MakePoint(ST_X(geom) + 3, ST_Y(geom) + 2)
))
)
FROM (SELECT 'POINT(5 5)'::geometry AS geom) AS a;

st_astext | st_astext
------------+--------------------------------
POINT(5 5) | POLYGON((2 3,2 7,8 7,8 3,2 3))
(1 row)


-- Kevin

Daniel Grum

unread,
Aug 20, 2009, 12:42:32 PM8/20/09
to Kevin Neufeld, PostGIS Mailing-List
Kevin Neufeld schrieb:
Your request nr.2 is perfect, thank you.
But can use this created polygon to selcet a part of another polygon, in
my case public.wald_by.the_geom.
Or do I have to save the selcted information in a table and use this for
the new request???
Because I need to selcet the other polygon to calculate the area of the
selected part, of public.wald_by.the_geom !

--Daniel

Kevin Neufeld

unread,
Aug 20, 2009, 12:57:41 PM8/20/09
to danie...@unibw.de, PostGIS Mailing-List
You mean like this?
SELECT ST_Intersection(
poly.geom,
ST_Expand(pt.geom, 2))
FROM mypolygontable poly, mypointtable pt
WHERE poly.geom && ST_Expand(pt.geom, 2);

Yes, you can expand the bounding boxes on fly and use it to intersect another geometry.

Cheers,

Daniel Grum

unread,
Aug 24, 2009, 5:09:50 AM8/24/09
to Kevin Neufeld, PostGIS Mailing-List
Kevin Neufeld schrieb:

> You mean like this?
> SELECT ST_Intersection(
> poly.geom,
> ST_Expand(pt.geom, 2))
> FROM mypolygontable poly, mypointtable pt
> WHERE poly.geom && ST_Expand(pt.geom, 2);
>
> Yes, you can expand the bounding boxes on fly and use it to intersect
> another geometry.
>
> Cheers,
> -- Kevin
>
> Daniel Grum wrote:
>> Your request nr.2 is perfect, thank you.
>> But can use this created polygon to selcet a part of another polygon,
>> in my case public.wald_by.the_geom.
>> Or do I have to save the selcted information in a table and use this
>> for the new request???
>> Because I need to selcet the other polygon to calculate the area of
>> the selected part, of public.wald_by.the_geom !
>>
>> --Daniel
The SQL you have given me, seems to be not correct, because the area is
NULL.
Here the geometry that came as an result:
"0107000020EB7A000000000000"

I changed the second paramter in the ST_Expand from 2 to 20 and after
this from 20 to 200 but the result was the same.
I tried to load the result of the SQL --> I saved it as a VIEW.
But in mapbender there wasn't shown any area???!!!

-- Daniel

Daniel Grum

unread,
Aug 24, 2009, 9:44:26 AM8/24/09
to Kevin Neufeld, PostGIS Mailing-List
Kevin Neufeld schrieb:

> You mean like this?
> SELECT ST_Intersection(
> poly.geom,
> ST_Expand(pt.geom, 2))
> FROM mypolygontable poly, mypointtable pt
> WHERE poly.geom && ST_Expand(pt.geom, 2);
>
> Yes, you can expand the bounding boxes on fly and use it to intersect
> another geometry.
>
> Cheers,
> -- Kevin
>
> Daniel Grum wrote:
>> Your request nr.2 is perfect, thank you.
>> But can use this created polygon to selcet a part of another polygon,
>> in my case public.wald_by.the_geom.
>> Or do I have to save the selcted information in a table and use this
>> for the new request???
>> Because I need to selcet the other polygon to calculate the area of
>> the selected part, of public.wald_by.the_geom !
>>
>> --Daniel
>
It works, thx
Reply all
Reply to author
Forward
0 new messages