[GENERAL] Error in creating function

2007-12-06 Thread Yancho
I am trying to create a function, which takes the nearest 3 hospitals
to a point making use of a PostGIS function), and then check each
hospital for the exact distance on roads (by making use of a pgRouting
function).

Below please find a copy of my function, and u can also find it
highlighted here : http://yancho.pastebin.com/f13cc045e

CREATE OR REPLACE FUNCTION near_hospital(text, integer, integer)
  RETURNS integer AS
$BODY$

DECLARE
pojnt ALIAS FOR $1;
box ALIAS FOR $2;
dist ALIAS FOR $3;

distances RECORD;

nearest RECORD;


BEGIN


   nearest.dist := 10;

   FOR distances IN

  select astext(h.the_geom) as
hospital_location from hospitals h where
 (
 h.the_geom  expand (pointfromtext(pojnt),
10) and
 distance ( h.the_geom ,
pointfromtext(pojnt) )  15
 )
order by distance (h.the_geom ,
pointfromtext(pojnt)) ASC
limit 3;
LOOP

   select INTO hospital gid, the_geom, length(the_geom) AS
dist from shootingstar_sp
  ( 'streets',

(
select s.gid from streets s, hospitals h
where
source = (
   select
give_source(distances.hospital_location,10,15))
limit 1
)

,

(
select gid from streets where
target = (select 
give_target(pojnt,10,15))
limit 1
)

,
   5000,
   'length',
   true,
   true
  );


  IF hospital.dist  nearest.dist  THEN
  nearest.dist := hospital.dist;
  nearest.gid := hospital.gid;

  select INTO nearest name from hospital h
 where h.gid = hospital.gid ;

  END IF;

   END LOOP;

   RETURN nearest.gid;

END;

' language 'plpgsql';


The error being given by pgAdminIII is : unterminated dollar-quoted
string at or near $BODY$ [then some garbled text] for $1;

Any help will be extremely appreciated!

Thanks and regards

Matthew

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


[GENERAL] Open Source GIS System

2007-11-12 Thread Yancho
Hi,

I am preparing to build up a GIS system as part of my University
Masters Thesis. My final aim is to build a system where the user
inputs (or via GPS) inputs the location where he is and the location
where he want to go and gets the route planned. My main concern will
be that the driver can decide which route to take, if the shortest
distance, least time consuming or else least fuel consumption. Also
the route planned has to be aware of certain problems that the network
can find, for example road blocks, or some other type of incidents /
accidents. May I point out that I need to use only Open Source
Software.

I am think to use this algorithm to work with :
1. User inputs starting and ending
2. A script checks the options sent by the user
3. The streets which are blocked by something are mentioned as
inactive
4. A route is planned
5. The route is sent as an image to user
6. Wait 20 seconds
7. If start = end goto 10 Else :
8. Reread position (maybe using GPS.. or random new coordinates from
the map)
9. Go back to step 3
10. Send a msg : Thanks for driving safely or some other msg :)


Now, from the research I have done, it seems I need these Open Source
software, and this is what I got the presumption they will suffice
for :

PostgreSQL + PostGIS : Basically where to store the data
GRASS : For data Management
QGis (with GRASS extension) : Frontend for viewing the data
pgRouting : To create the route
OpenLayers : To create the image to be sent to the user's browser. I
want a static image which then will be updated every lets say 20
seconds.
PHP : To write the scripts to communicate with the PostGIS / User +
HTML 4.0

What do you think about my setup please? Is there some software you
think I should replace or rethink about using? Following my algorithm
and the software I am looking at, I think that I need to do like
this :
a. A script in PHP which captures the data and then echo the image
using OpenLayers to the user's browser
b. QGIS (with the save file of the base-map and the roads marked)
which allows the Road Network Admin to disable any Road, and another
PHP Script that can read the starting, ending coordinates of the road
and allow a User to report that there are problems in the road.

Any comments / suggestions / change of plans would be extremely
appreciated at this stage,

Whilst thanking all of you for taking time to read this post, I really
wish to hear your opinions.

Thanks and Regards

Matthew


---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings