Caro-COOPS.org Discussion Board Forum Index Caro-COOPS.org Discussion Board
Discussion area for Caro-COOPS-related initiatives
 
 FAQFAQ   Search   MemberlistMemberlist   UsergroupsUsergroups   Calendar   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

example of how to render particle trajectory data (drifters)

 
       Caro-COOPS.org Discussion Board Forum Index
   -> Tools, GIS (Geographic Information Systems)
   -> MapServer, MapServer
View previous topic :: View next topic  
Author Message
cpurvis



Joined: 24 Feb 2025
Posts: 255

Posted: Wed Aug 04, 2025 3:38 pm    Post subject: example of how to render particle trajectory data (drifters)

Working demo is here: http://nautilus.baruch.sc.edu/~cpurvis/particle_demo/particle.phtml.

How to go from ASCII particle data to time-based maps.

Its original inspiration is from here: http://nautilus.baruch.sc.edu/rs.

This working example is based on PHP and MapScript w/ Mapserver 4.2 doing all the dirty work + PostGIS and PostgreSQL.

Step one is to get the data into the database.

The original data looks like this:
Code:
2025-05-10 17:40:00 | -5.666 | 43.544
2025-05-10 18:17:00 | -5.660 | 43.543
2025-05-10 19:18:00 | -5.661 | 43.545
2025-05-10 21:13:00 | -5.662 | 43.546
2025-05-10 22:06:00 | -5.667 | 43.544
2025-05-10 23:46:00 | -5.662 | 43.547
2025-05-11 02:11:00 | -5.664 | 43.543
2025-05-11 03:51:00 | -5.663 | 43.545
2025-05-11 04:53:00 | -5.695 | 43.611
2025-05-11 05:32:00 | -5.745 | 43.694
2025-05-11 05:53:00 | -5.724 | 43.727
2025-05-11 06:31:00 | -5.804 | 43.797
2025-05-11 07:32:00 | -5.850 | 43.904
2025-05-11 07:51:00 | -5.884 | 43.917
2025-05-11 09:12:00 | -5.869 | 43.909
2025-05-11 09:33:00 | -5.863 | 43.903

See particle_test.sql.txt for the actual INSERT and TABLE creation statements. This will create a new table, particle_test in an already existing myGISdb PostgreSQL w/ PostGIS database. (NOTE: You could also create a shapefile to do the same thing.)

The back-end is composed of two PHP pages. The first, particle.phtml, controls what time_stamp is passed to the map. It is pretty straightforward since it calls itself w/ the new (or no) time_stamp. It is attached as particle.phtml.txt.

The brains are mostly in the PHP file mk_particle_map.php (attached as mk_particle_map.php.txt). Of course, it depends heavily on the original .map running the show. It is attached as particle_test_map.txt.

The important part of the .map looks like this:
Code:
  LAYER
    NAME "particle_trajectories_old"
    STATUS ON
    DATA "the_geom from particle_test"
    TYPE POINT
    CONNECTIONTYPE POSTGIS
    CONNECTION "***"
    TRANSPARENCY 20
    CLASSITEM 'time_stamp'
    CLASS
      SYMBOL 'circle'
      SIZE 5
      COLOR 255 0 0
    END
  END
  LAYER
    NAME "particle_trajectories"
    STATUS ON
    DATA "the_geom from particle_test"
    TYPE POINT
    CONNECTIONTYPE POSTGIS
    CONNECTION "***"
    CLASSITEM 'time_stamp'
    CLASS
      SYMBOL 'circle'
      SIZE 6
      COLOR 255 0 0
    END
    CLASS
      SYMBOL 'circle'
      SIZE 5
      COLOR 255 32 32
    END
    CLASS
      SYMBOL 'circle'
      SIZE 5
      COLOR 255 64 64
    END
    CLASS
      SYMBOL 'circle'
      SIZE 5
      COLOR 255 96 96
    END
    CLASS
      SYMBOL 'circle'
      SIZE 5
      COLOR 255 128 128
    END
  END


I'll hopefully have more time to go into more detail, but the essence is this:

* Two layers control the particle dots you see. The first (particle_trajectories_old) shows a transparentish red layer of dots for dots that are older than whatever time_stamp you're looking at. The second layer (particle_trajectories) shows different sized dots at varying shades of red to show (in our case) the most recent 5 hours relative to the time_stamp.

* What dots to show for a given time_stamp are controlled differently for the two layers. particle_trajectories_old is controlled by a FILTER statement since we want to show all the old dots relative to a time_stamp. Its WHERE clause might look something like this:
Code:
date_trunc('hour',time_stamp) < date_trunc('hour',timestamp without time zone '2025-05-11 02:00:00')

As you already know, the particle_trajectories is broken down into classes. Well, we use an EXPRESSION to control which class gets shaded a darker red and is a bigger dot. I assume that class0 is the biggest and reddest (and, hence, equal to time_stamp). If you look in the mk_particle_map.php, the line
Code:
$this_class->setexpression('/'.$time_stamp.'/');

does that for us. It does a regular expression on the results from the regular query to compare the yyyy/mm/dd hh part of the data w/ the computed time_stamp.

And there you have it!

Look at the working demo at the URL at the top of this page as well as a link from that page to another example of trajectories based on SEACOOS model data (it's an animation).



particle_test_map.txt
 Description:

Download
 Filename:  particle_test_map.txt
 Filesize:  4.88 KB
 Downloaded:  114 Time(s)


particle.phtml.txt
 Description:

Download
 Filename:  particle.phtml.txt
 Filesize:  3.05 KB
 Downloaded:  45 Time(s)


mk_particle_map.php.txt
 Description:
Only the CONNECTION string has been removed.

Download
 Filename:  mk_particle_map.php.txt
 Filesize:  1.29 KB
 Downloaded:  102 Time(s)


particle_test.sql.txt
 Description:

Download
 Filename:  particle_test.sql.txt
 Filesize:  2.9 KB
 Downloaded:  94 Time(s)

Back to top
Display posts from previous:   
       Caro-COOPS.org Discussion Board Forum Index
   -> Tools, GIS (Geographic Information Systems)
   -> MapServer, MapServer
All times are GMT - 5 Hours
Page 1 of 1

 
Jump to: 
 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB 2.0.4 © 2001, 2002 phpBB Group