I would like to trigger NOTIFY only on points that are in a certain PostGIS region. I have a table called car. I want to get a NOTIFYcation every time a car updates it's coordinate or a new car is updated, but only in a certain region. Essentially I want to monitor for changes in rows that have a point that is located in the region of my interest.
I would be grateful for any hints in the right direction. Thank you in advance.
if I understand correctly, you should follow a method like this,
1- fist of all you create a "view" which is return boolean value if your point of car and region interacts with each other. For this st_contains or st_intersects function be useful.
2- Create a trigger on the car table and the trigger should run every action of update or insert.
3- The trigger affects rows just be returned of the first view that you make
this might not be the best way but I think it can solve your situation.
Related
In my model I want to loop through the database which contains multiple columns (see example) by an event. The idea behind it is that I want to create dynamic events based on the rows in the database.
But I've no clue how to iterate through a database in anylogic and also was not able to find an example of a loop with a database.
The dummycode of my problem would look something like this:
For order in orderdatabase:
Create order based on (order.name, order.quantity, order.arrivaltime, order.deliverylocation)
Where order in the loop is every row of the database, and the value on which the creation is based based on the different column values of that specific row.
Can somebody give me a simple example of how to create such a loop for this specific problem.
Thanks in advance.
Use the database query wizard:
put your cursor into a code field
this will allow you to open the database wizard
select what you need (in your case, you want the "iterate over returned rows and do something" option
Click ok
adjust the dummy code to make it do what you want
For details and examples, check the example models and the AnyLogic help, explaining all options in detail.
My model has a collection of trucks, where the Source block provides each truck with a unique ID. I also have a database containing information on the vehicles' movements.
No column has unique values, but together the trip_start_date and vehicle_id should be a unique set. I'm trying to structure a moveTo block such that when a date in the trip_start_time column is reached during the model runtime, then the agent with that vehicle_id as a parameter will move to the lat/long in a certain amount of time.
However, I'm getting an "empty database value result." I'm wondering if this is because it's expecting every model date to have an entry? I considered making a function that's called when a date in the database is encountered, but I was told that the moveTo block should be able to handle this activity. Help in resolving this issue would be greatly appreciated!
The way you are trying to use the MoveTo block is not correct. It is hard to explain here but I think you need to go through a few tutorials inside help to get a better fundamental understanding.
However, below is a reproducible example of the behavior I think you want to implement, but using agent-based approach instead of a process-centric or discrete event approach.
I have an agent called Vehicle with a ID called vehicle ID.
There is a Dynamic event has all the parameters found in the DB
Then at the start of the model, we generate all the moveTo events found in the Database using the code below.
List<Tuple> rows = selectFrom(db_table)
.where(db_table.vehicle_id.eq(vehicleID))
.list();
for (Tuple row : rows) {
//What is the start time of the movement
double timeToTripBegin = dateToTime(row.get( db_table.trip_begin_time ));
//Lets create a new movement event to trigger the movement int he future
create_MoveToLocation(timeToTripBegin,
row.get( db_table.latitude ),
row.get( db_table.longitude ),
row.get( db_table.trip_duration_h ));
}
This event will then execute the move to when the time arrives
I'm aiming to create a data table with specific color for each line in vega.
Actually i manage to do it like that
My problem is : when I click on a rectangle, it change the color of all the rectangle not only the one I clicked on.
I did not found a way to make my signals values dependent on each of my row so i decided to add a data to each row. At first i tried to use an aggregation but none of the aggregation i found allow me to set a static value in a field.
Then i thought a calculate could do it but it results in a Property calculate is not allowed
Right now I'm stuck and I don't know at all how i could do so.
If anyone has an idea on how I could do it, I would really appreciate. Thanks by advance
OK... let me retry the question.
I'll just walk through the steps I (wrongly) assumed would work.
Create a data table in excel with passenger info (id, flight_time, type, class, qty...), note that the table is sorted by id... not flight_time.
Import this database into anylogic.
Create a population of agents (Passenger/Passengers) from the data table (one/row).
Create a schedule that addresses the Start Column as flight_time and Value column as qty (for this job I'm only sending one passenger at a time therefore qty = 1 for each row).
Set the pedSource to arrive according to schedule and to use the Passenger Agent as the New pedestrian.
So here is where I'm losing it. When I run this model the new Passengers do not have any parameters associated from the data table. The pedestrian id is some weird number (say 3000 or so). I can click on the Passengers icon during run time and scroll through the created agents (all of the parameter data is there and correctly assigned), but I'm not sure how to associate the new Agents in the run-time model with the population of Passengers agents.
Am I missing a step here? I was thinking that if I import a population of agents from a data table and then have each show up at a particular time in the model that I could then do some calculations with regard to each such as ped.exitTime = time() - ped.flightTime - ped.bufferTime.
I'm just not understanding why the table data is not available for use during run-time through ped? Is there another mapping step that must be performed to push the data to the ped agnets?
I'm at an impasse at this point. I hope this question is described more clearly and your feedback is appreciated.
Several things are wrong here.
You do not create agents in a pop first and then try to reuse them in a PedSource. The latter creates agents itself.
You don't seem to create pedestrians but just agents
you are not mapping the data to parameters
Quick guide to help:
create custom agent type "MyPed" . Make sure its "use in flowchart" property is set to "Pedestrian"
add 1 param into "MyPed" for each dbase table column
set your PedSource to "calls of inject()" function for its arrivals
delete your schedule, you cannot get the data you need
USe a DynamicEvent. Include 1 parameter argument for each dbase column. On Startup of main, loop across all dbase entries and create a dynamic event with the current row-data.
in the action of the DynEvent, call myPedSource.inject(1) and then manually fill that ped with the data from the arguments
This is not straightforward, especially the DynEvent stuff. So do more research in the AL help to understand these and how they work, check example models...
I am working on a project where we are going to be looking at finding the shortest/fastest route from point A to point B. I've been looking at the tables generated by the osm2pgsql. And I'm wondering how would I represent a road obstructed after the osm has been loaded into our database. Our project will rely on osm to map out all of the roads we will also have an operator looking at live video footage of roads. At which point if the operator see's a road is obstructed we want to update the database to reflect this road obstructed say by a downed tree.
I've been looking at all of the columns and the only one that stands out in my head is barrier. I have been unable to find any documentation on what each column represents and how pg_route takes each into consideration when creating a route. What I'm looking for is a column that when pg_route looks in the database and sees a road it says oh that roads blocked skip it?
This is good question for gis.se...
First thing is pg_routing can't route via data generated by osm2pgsql - this data is not a network. You need data generated by osm2po or osm2pgrouting and this data is quite different.
Second thing is - there is no such column. In every pg_routing function you're passing sql which will select data for route search so you're deciding which edge will be in this dataset and which not - it's not a problem to add extra column to table with edges.
Here is link to pgrouting workshop it will guide you through all process from import of data to first generated route. It's using osm2pgroutin to import data, but I suggest you use osm2po instead.
So as Jendrusk mentioned, when you generate a route you will pass the function a SQL query to select the edges for the graph you want to solve, 'select * from edges where the_geom && <bbox>' You can model blockages using point and radius, lines, or polygons that you want the route to avoid by adding to the query above avoidance zones like:
'select * from edges where the_geom && <bbox> and not st_dwithin(the_geom, point, radius) and not stdwithin(the_geom, line_or_polygon, 0.0)'
If you have lots of these avoidances then put them in a table and do a join to eliminate the edges that are used to build the graph. If the edges are not there the route is forces to find a way around the avoidance.