Obe, Regina | 1 Apr 2007 09:25
Favicon

RE: find single bbox of multiple objects

What about extent
SELECT extent(the_geom) from yourtable where id IN(1,2,3)

From: postgis-users-bounces <at> postgis.refractions.net on behalf of Richard Greenwood
Sent: Sat 3/31/2007 2:05 PM
To: PostGIS Users Discussion
Subject: [postgis-users] find single bbox of multiple objects

I need to find the bounding box (minimum bounding rectangle) of a
group of objects. I am trying things like:
   select box(the_geom) where id in (1, 2, 3);
Which gives me 3 boxes. But I want a single box representing the
bounds of all three objects.

Thanks,
Rich

--
Richard Greenwood
richard.greenwood <at> gmail.com
www.greenwoodmap.com
_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
Richard Greenwood | 1 Apr 2007 15:44
Picon

Re: find single bbox of multiple objects

On 4/1/07, Obe, Regina <robe.dnd <at> cityofboston.gov> wrote:
>
>
>
> What about extent
> SELECT extent(the_geom) from yourtable where id IN(1,2,3)

Perfect, thanks so much!

Rich

--

-- 
Richard Greenwood
richard.greenwood <at> gmail.com
www.greenwoodmap.com
Obe, Regina | 1 Apr 2007 23:33
Favicon

RE: Indexes not being used

>

I assume the srid of your t.geometry field is 4326.
 
How do you have your index specified?  If you have it something like
 
CREATE INDEX idx_pt_madeira_topnymy_geometry ON  pt_madeira_toponymy USING GIST(transform(geometry, 4326));
 
rather than
CREATE INDEX idx_pt_madeira_topnymy_geometry ON  pt_madeira_toponymy USING GIST(geometry);
 
I don't think it will recognize it as a valid index for your query since your query is using geometry rather than transform(geometry, 4326)
 
Other thing to check - you should have an index on your parish field.  I think that may have better selectivity depending on how many parish are 'SE'
 
Hope that helps,
Regina
 

From: postgis-users-bounces <at> postgis.refractions.net on behalf of Pedro Doria Meunier
Sent: Sat 3/31/2007 2:57 PM
To: 'PostGIS Users Discussion'
Subject: [postgis-users] Indexes not being used

Hi all (with a special wink to Regina ;- )

 

This is the query not using indices:

 

SELECT parish,county,geometry FROM pt_madeira_toponymy as t WHERE parish=upper('se') AND

  t.geometry && geomfromtext('POINT(-16.9213592631455 32.6437878212273)',4326) AND intersects(geomfromtext('POINT(-16.9213592631455 32.6437878212273)',4326), t.geometry);

 

As you can plainly see it checks if a point is inside some polygon.

 

EXPLAIN ANALYZE returns this:

"Seq Scan on pt_madeira_toponymy t  (cost=0.00..3.03 rows=1 width=96) (actual time=1.086..1.278 rows=1 loops=1)"

"  Filter: ((parish = 'SE'::text) AND (geometry && '0101000020E61000009B135F33DEEB30C0FFDDAAA367524040'::geometry) AND intersects('0101000020E61000009B135F33DEEB30C0FFDDAAA367524040'::geometry, geometry))"

"Total runtime: 1.312 ms"

 

The toponymy has two indices: one for 4326 and another for 32628 using GiST.

 

Is the intersects function not using indices at all??

 

Already thankful for any ideas,

With best regards,

Pedro Doria Meunier.

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
Pedro Doria Meunier | 2 Apr 2007 00:10
Favicon

RE: Indexes not being used

Hello Regina,

 

Txs for replying.

 

You’re right. I was missing an index for the text fields. I realized this and immediately applied the theory with grim results… L

 

It turns out (?) that one as to use TSearch2 to have the indices fired up for text fields… Someone please rebate me if I’m wrong.

 

Anyway I’m still not ready to mess up with my tables’ schema in case someone comes up with a more enlightened solution…

 

Best regards,

Pedro.

 

 

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Obe, Regina
Sent: domingo, 1 de Abril de 2007 22:34
To: PostGIS Users Discussion
Subject: RE: [postgis-users] Indexes not being used

 

I assume the srid of your t.geometry field is 4326.

 

How do you have your index specified?  If you have it something like

 

CREATE INDEX idx_pt_madeira_topnymy_geometry ON  pt_madeira_toponymy USING GIST(transform(geometry, 4326));

 

rather than

CREATE INDEX idx_pt_madeira_topnymy_geometry ON  pt_madeira_toponymy USING GIST(geometry);

 

I don't think it will recognize it as a valid index for your query since your query is using geometry rather than transform(geometry, 4326)

 

Other thing to check - you should have an index on your parish field.  I think that may have better selectivity depending on how many parish are 'SE'

 

Hope that helps,

Regina

 

 

From: postgis-users-bounces <at> postgis.refractions.net on behalf of Pedro Doria Meunier
Sent: Sat 3/31/2007 2:57 PM
To: 'PostGIS Users Discussion'
Subject: [postgis-users] Indexes not being used

Hi all (with a special wink to Regina ;- )

 

This is the query not using indices:

 

SELECT parish,county,geometry FROM pt_madeira_toponymy as t WHERE parish=upper('se') AND

  t.geometry && geomfromtext('POINT(-16.9213592631455 32.6437878212273)',4326) AND intersects(geomfromtext('POINT(-16.9213592631455 32.6437878212273)',4326), t.geometry);

 

As you can plainly see it checks if a point is inside some polygon.

 

EXPLAIN ANALYZE returns this:

"Seq Scan on pt_madeira_toponymy t  (cost=0.00..3.03 rows=1 width=96) (actual time=1.086..1.278 rows=1 loops=1)"

"  Filter: ((parish = 'SE'::text) AND (geometry && '0101000020E61000009B135F33DEEB30C0FFDDAAA367524040'::geometry) AND intersects('0101000020E61000009B135F33DEEB30C0FFDDAAA367524040'::geometry, geometry))"

"Total runtime: 1.312 ms"

 

The toponymy has two indices: one for 4326 and another for 32628 using GiST.

 

Is the intersects function not using indices at all??

 

Already thankful for any ideas,

With best regards,

Pedro Doria Meunier.

 


The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended solely for the
addressee. If you received this in error, please contact the sender
and delete the material from any computer.

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
Pedro Doria Meunier | 2 Apr 2007 03:50
Favicon

10 closest units

Hi All,

 

<at> Regina:

Remember you helped me with the 10 closest units to a given point? This was it:

(original layers srid==4326 – I want *meters* so the transform at play)

SELECT u.id, u.friendly_name, u.curr_location, t.oid, distance(transform(u.curr_location,32628), transform(t.geometry, 32628)) AS thedistance, u.mobile FROM units AS u, (SELECT roads.oid, roads.geometry FROM roads WHERE name=’N17’ LIMIT 1) AS t

ORDER BY thedistance LIMIT 10;

 

(this query returns the 1st found line segment labelled ‘N17’ which is 68Kms away when the unit is actually 1.8 meters away from the closest line segment of the same label)

 

<at> All

This actually returns the FIRST occurrence of ‘N17’ (the sample).

This is *NOT* necessarily the closest road to the unit’s current location.

 

I’ve melted half-a-dozen neurons (mainly due to tiredness at the time of this writing :] )trying to figure out how can I implement the distance bit in the sub-query…

 

Given example for ONE unit:

select u.friendly_name, distance(transform(u.curr_location, 32628),

transform(geometry,32628)) as thedistance

from pt_mainland_roads as r, units as u

where name='N17' AND u.curr_location && r.geometry order by thedistance LIMIT 1;

 

(this returns the correct result)

 

So to summarize things:

I need help with a query that returns the *FIRST TEN* units to the *closest given* road.

(Keep in mind that multiple line segments with the same name exist – I need the closest)

 

Will try again tomorrow with a clear head but in the meantime:

Any help would be most appreciated!

 

Best regards,

Pedro Doria Meunier.

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
Obe, Regina | 2 Apr 2007 14:43
Favicon

RE: 10 closest units

I'm not sure how slow this would be depending on how many line segments you have by name, but it seems the most speedy to write.  Basically I think you want to collect all your roads of N17 into a single geometry so that you can then apply a single distance check call.
 
So something like
 

select u.friendly_name, distance(transform(u.curr_location, 32628),

transform(rc.agg_geometry,32628)) as thedistance

from (SELECT collect(r.geometry) as agg_geometry FROM pt_mainland_roads r WHERE r.name = 'N17') rc, units as u

where rc.agg_geometry && u.curr_location order by thedistance LIMIT 10;

 

If you have some units that are not in the bounding box of a road that would be in the top 10, then you may want to change your where clause to

 

expand(rc.agg_geometry, <somevalue>) && u.curr_location

 

Hope that helps,

Regina


From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Pedro Doria Meunier
Sent: Sunday, April 01, 2007 9:50 PM
To: 'PostGIS Users Discussion'
Subject: [postgis-users] 10 closest units
Importance: High

Hi All,

 

<at> Regina:

Remember you helped me with the 10 closest units to a given point? This was it:

(original layers srid==4326 – I want *meters* so the transform at play)

SELECT u.id, u.friendly_name, u.curr_location, t.oid, distance(transform(u.curr_location,32628), transform(t.geometry, 32628)) AS thedistance, u.mobile FROM units AS u, (SELECT roads.oid, roads.geometry FROM roads WHERE name=’N17’ LIMIT 1) AS t

ORDER BY thedistance LIMIT 10;

 

(this query returns the 1st found line segment labelled ‘N17’ which is 68Kms away when the unit is actually 1.8 meters away from the closest line segment of the same label)

 

<at> All

This actually returns the FIRST occurrence of ‘N17’ (the sample).

This is *NOT* necessarily the closest road to the unit’s current location.

 

I’ve melted half-a-dozen neurons (mainly due to tiredness at the time of this writing :] )trying to figure out how can I implement the distance bit in the sub-query…

 

Given example for ONE unit:

select u.friendly_name, distance(transform(u.curr_location, 32628),

transform(geometry,32628)) as thedistance

from pt_mainland_roads as r, units as u

where name='N17' AND u.curr_location && r.geometry order by thedistance LIMIT 1;

 

(this returns the correct result)

 

So to summarize things:

I need help with a query that returns the *FIRST TEN* units to the *closest given* road.

(Keep in mind that multiple line segments with the same name exist – I need the closest)

 

Will try again tomorrow with a clear head but in the meantime:

Any help would be most appreciated!

 

Best regards,

Pedro Doria Meunier.



The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended solely for the
addressee. If you received this in error, please contact the sender
and delete the material from any computer.

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
mfrumin | 2 Apr 2007 15:11

SRID for analyzing a USA national data set in Meters


I have a data set that includes points all over the United States in lat/lng
(say, SRID = 4326) but I need to do some analysis on these data in real
units, say meters.  So, my task is to select an appropriate SRID that will
work reasonably well for the whole USA to reproject lat/lng into meters.  
There are a bazillion SRID's available. Any suggestions?

This analysis doesn't have to be super-precise, so I'm not so concerned with
the limitations of a national projection (as opposed to state/region).

thanks,
Michael

--

-- 
View this message in context: http://www.nabble.com/SRID-for-analyzing-a-USA-national-data-set-in-Meters-tf3505664.html#a9790471
Sent from the PostGIS - User mailing list archive at Nabble.com.
Pedro Doria Meunier | 2 Apr 2007 15:29
Favicon

RE: SRID for analyzing a USA national data set in Meters

Hello Michael,

You determine the correct SRID with this bit of code (PHP):
(the $loc was obtained from a SELECT with the astext(geometry) function)

The idea behind this is summarized in the UtmZoneFromLong() function.
Pick a Long value and calculate the utm zone for it.
Then use the SridFromUtmZone() function to get the srid from the given mask
(see below) --> this queries spatial_ref_sys with the calculated $utm param.
SELECT srid FROM spatial_ref_sys WHERE srtext LIKE 'PROJCS[\"WGS 84 / UTM
zone $utm%' LIMIT 1

// extract the POINT geometry
$geometry = str_replace("POINT(","", $loc);
$geometry = str_replace(")","",$geometry);
$coordinate = explode(" ",$geometry);
$lon=$coordinate[0];
$lat=$coordinate[1];

// get utm zone from coordinates
$utm=UtmZoneFromLong($lon);
// get srid from the spatial_ref_sys table for the given utm zone
// add N or S
if($lat>=0) $utm.="N";
else $utm.="S";
$srid=SridFromUtmZone($utm, $connection);

// determine UTM zone from LonLat coordinates
// params $long: longitude
// returns (int) utm
function UtmZoneFromLong($lon) {
	$utm = floor(($lon + 180) / 6) + 1;
	return $utm;
}

// query the spatial_ref_sys table for the srid of the given utm zone
// params $utm: utm zone string (MUST BE TRAILED WITH 'N' OR 'S'!), $conn:
connection to the db
// returns (int) srid
function SridFromUtmZone($utm, $conn){
$myresult = pg_exec($conn, "SELECT srid FROM spatial_ref_sys WHERE srtext
LIKE 'PROJCS[\"WGS 84 / UTM zone $utm%' LIMIT 1");
$srid=pg_result($myresult, 0, 0);
return $srid;
}

HTH,
Pedro Doria Meunier

-----Original Message-----
From: postgis-users-bounces <at> postgis.refractions.net
[mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of mfrumin
Sent: segunda-feira, 2 de Abril de 2007 14:12
To: postgis-users <at> postgis.refractions.net
Subject: [postgis-users] SRID for analyzing a USA national data set in
Meters

I have a data set that includes points all over the United States in lat/lng
(say, SRID = 4326) but I need to do some analysis on these data in real
units, say meters.  So, my task is to select an appropriate SRID that will
work reasonably well for the whole USA to reproject lat/lng into meters.  
There are a bazillion SRID's available. Any suggestions?

This analysis doesn't have to be super-precise, so I'm not so concerned with
the limitations of a national projection (as opposed to state/region).

thanks,
Michael

--

-- 
View this message in context:
http://www.nabble.com/SRID-for-analyzing-a-USA-national-data-set-in-Meters-t
f3505664.html#a9790471
Sent from the PostGIS - User mailing list archive at Nabble.com.

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
Pedro Doria Meunier | 2 Apr 2007 15:32
Favicon

RE: 10 closest units

Regina,

 

You’re simply an angel! Thank you!

 

Just one question:

The expand(rc.agg_geometry, 0.5) uses *degrees*, right?

 

All the best,

Pedro.

 

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Obe, Regina
Sent: segunda-feira, 2 de Abril de 2007 13:43
To: PostGIS Users Discussion
Subject: RE: [postgis-users] 10 closest units

 

I'm not sure how slow this would be depending on how many line segments you have by name, but it seems the most speedy to write.  Basically I think you want to collect all your roads of N17 into a single geometry so that you can then apply a single distance check call.

 

So something like

 

select u.friendly_name, distance(transform(u.curr_location, 32628),

transform(rc.agg_geometry,32628)) as thedistance

from (SELECT collect(r.geometry) as agg_geometry FROM pt_mainland_roads r WHERE r.name = 'N17') rc, units as u

where rc.agg_geometry && u.curr_location order by thedistance LIMIT 10;

 

If you have some units that are not in the bounding box of a road that would be in the top 10, then you may want to change your where clause to

 

expand(rc.agg_geometry, <somevalue>)&& u.curr_location

 

Hope that helps,

Regina

 

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Pedro Doria Meunier
Sent: Sunday, April 01, 2007 9:50 PM
To: 'PostGIS Users Discussion'
Subject: [postgis-users] 10 closest units
Importance: High

Hi All,

 

<at> Regina:

Remember you helped me with the 10 closest units to a given point? This was it:

(original layers srid==4326 – I want *meters* so the transform at play)

SELECT u.id, u.friendly_name, u.curr_location, t.oid, distance(transform(u.curr_location,32628), transform(t.geometry, 32628)) AS thedistance, u.mobile FROM units AS u, (SELECT roads.oid, roads.geometry FROM roads WHERE name=’N17’ LIMIT 1) AS t

ORDER BY thedistance LIMIT 10;

 

(this query returns the 1st found line segment labelled ‘N17’ which is 68Kms away when the unit is actually 1.8 meters away from the closest line segment of the same label)

 

<at> All

This actually returns the FIRST occurrence of ‘N17’ (the sample).

This is *NOT* necessarily the closest road to the unit’s current location.

 

I’ve melted half-a-dozen neurons (mainly due to tiredness at the time of this writing :] )trying to figure out how can I implement the distance bit in the sub-query…

 

Given example for ONE unit:

select u.friendly_name, distance(transform(u.curr_location, 32628),

transform(geometry,32628)) as thedistance

from pt_mainland_roads as r, units as u

where name='N17' AND u.curr_location && r.geometry order by thedistance LIMIT 1;

 

(this returns the correct result)

 

So to summarize things:

I need help with a query that returns the *FIRST TEN* units to the *closest given* road.

(Keep in mind that multiple line segments with the same name exist – I need the closest)

 

Will try again tomorrow with a clear head but in the meantime:

Any help would be most appreciated!

 

Best regards,

Pedro Doria Meunier.

 


The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended solely for the
addressee. If you received this in error, please contact the sender
and delete the material from any computer.

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
Obe, Regina | 2 Apr 2007 15:37
Favicon

RE: 10 closest units

Its whatever the metric of your r.geometry field so if that is in degrees then yes it would be in degrees.
 
Thanks,
Regina

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Pedro Doria Meunier
Sent: Monday, April 02, 2007 9:32 AM
To: 'PostGIS Users Discussion'
Subject: RE: [postgis-users] 10 closest units
Importance: High

Regina,

 

You’re simply an angel! Thank you!

 

Just one question:

The expand(rc.agg_geometry, 0.5) uses *degrees*, right?

 

All the best,

Pedro.

 

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Obe, Regina
Sent: segunda-feira, 2 de Abril de 2007 13:43
To: PostGIS Users Discussion
Subject: RE: [postgis-users] 10 closest units

 

I'm not sure how slow this would be depending on how many line segments you have by name, but it seems the most speedy to write.  Basically I think you want to collect all your roads of N17 into a single geometry so that you can then apply a single distance check call.

 

So something like

 

select u.friendly_name, distance(transform(u.curr_location, 32628),

transform(rc.agg_geometry,32628)) as thedistance

from (SELECT collect(r.geometry) as agg_geometry FROM pt_mainland_roads r WHERE r.name = 'N17') rc, units as u

where rc.agg_geometry && u.curr_location order by thedistance LIMIT 10;

 

If you have some units that are not in the bounding box of a road that would be in the top 10, then you may want to change your where clause to

 

expand(rc.agg_geometry, <somevalue>)&& u.curr_location

 

Hope that helps,

Regina

 

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Pedro Doria Meunier
Sent: Sunday, April 01, 2007 9:50 PM
To: 'PostGIS Users Discussion'
Subject: [postgis-users] 10 closest units
Importance: High

Hi All,

 

<at> Regina:

Remember you helped me with the 10 closest units to a given point? This was it:

(original layers srid==4326 – I want *meters* so the transform at play)

SELECT u.id, u.friendly_name, u.curr_location, t.oid, distance(transform(u.curr_location,32628), transform(t.geometry, 32628)) AS thedistance, u.mobile FROM units AS u, (SELECT roads.oid, roads.geometry FROM roads WHERE name=’N17’ LIMIT 1) AS t

ORDER BY thedistance LIMIT 10;

 

(this query returns the 1st found line segment labelled ‘N17’ which is 68Kms away when the unit is actually 1.8 meters away from the closest line segment of the same label)

 

<at> All

This actually returns the FIRST occurrence of ‘N17’ (the sample).

This is *NOT* necessarily the closest road to the unit’s current location.

 

I’ve melted half-a-dozen neurons (mainly due to tiredness at the time of this writing :] )trying to figure out how can I implement the distance bit in the sub-query…

 

Given example for ONE unit:

select u.friendly_name, distance(transform(u.curr_location, 32628),

transform(geometry,32628)) as thedistance

from pt_mainland_roads as r, units as u

where name='N17' AND u.curr_location && r.geometry order by thedistance LIMIT 1;

 

(this returns the correct result)

 

So to summarize things:

I need help with a query that returns the *FIRST TEN* units to the *closest given* road.

(Keep in mind that multiple line segments with the same name exist – I need the closest)

 

Will try again tomorrow with a clear head but in the meantime:

Any help would be most appreciated!

 

Best regards,

Pedro Doria Meunier.

 


The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended solely for the
addressee. If you received this in error, please contact the sender
and delete the material from any computer.

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

Gmane