Create turtles according to real population within vectors - vector

I want to create a population in NetLogo. Therefore, I want to create turtles within districts dependent on the population within this district. However, I am not entirely sure how to do that.
I got the population within the district as a patch-value like that:
gis:apply-coverage lor-dataset "GESBEV" population
But when I create the population with this I get the amount of people within a district in every patch instead of the amount of people within every district.
Is there the possibility to get the population value only once per district? I would also be grateful for any sources where I can do some further reading. I haven't found anything on my own.

There's probably a bunch of ways to go about this, but here are two options. First, some example data that I found on Esri Open data- the 2015 population data for Haiti. I extracted the shapefile and associated files into a folder called 'gis'. We'll use the population value found in the `gis:property-name': "POPULATION". With this setup:
extensions [ gis ]
globals [
state-layer
]
to setup
ca
resize-world 0 110 0 80
set-patch-size 6.5
set state-layer gis:load-dataset "gis/Population_2015.shp"
gis:set-world-envelope gis:envelope-of state-layer
gis:set-drawing-color white
gis:draw state-layer 1
reset-ticks
end
The first option is to just sprout the entire population (in this case, divided by 1000 to not spawn way too many turtles) at the centroid of each feature.
to sprout-at-centroid
foreach gis:feature-list-of state-layer [
state ->
; Get the population for this state, divided by 1000
; to get a reasonable number
let pop ( gis:property-value state "POPULATION" ) / 1000
; get the 'gis:location-of', an x-y list, for the
; centroid of the current state / district
let center gis:location-of gis:centroid-of state
; get the patch with the center xy values to sprout pop
ask patch first center last center [
sprout pop
]
]
end
Output looks like this:
Looks pretty good! All turtles are sprouted in the geographic center of each feature. Depending on your dataset however, you may run into problems. Notice that the island in the center is actually part of a multi-part feature, and so the population for that multi-part feature has spawned outside of the boundaries. This may not present a problem for you, depending on the shapes of your districts.
Option 2 is a little more convoluted, and you may introduce some rounding errors. It's also a lot slower, and depending on the size of your world and population could take a long time / you could run out of memory. First, get the count of your population and the count of patches contained within your districts. Then, divide the population by the patches in the district to get an average population per patch. Then, have each contained-patch sprout that number of turtles:
to apply-evenly
foreach gis:feature-list-of state-layer [
state ->
; Get the population for this state, divided by 10000
; to get a reasonable number
let pop ( gis:property-value state "POPULATION" ) / 1000
; Get the patches contained by the state. This is slow!
; Using 'gis:intersecting' alone is much faster, but results
; in overlaps as geographic boundaries don't align with patch boundaries
let target-patches ( patches gis:intersecting state ) with [ gis:contained-by? self state ]
if any? target-patches [
; Get the number of turtles that should be in each target-patch:
let avg-turtles round ( pop / count target-patches )
; Get the contained patches to sprout the appropriate number of turtles
ask target-patches [
sprout avg-turtles
]
]
]
end
Output for this one looks like:
But note that it does take much longer with larger populations than the one I used here as an example, especially since I divided by 1000. Also note that if your patches are too big to be contained by a certain district, you will not have any turtles spawn within your district (eg. the smaller islands off the south coast).
Hopefully this gets you pointed in the right direction!

Related

How to analyse spatial data using grid codes from a map

I would like to analyse movement data from a semi-captive animal population. We record their location every 5 mins using a location code which corresponds to a map of the reserve we have made ourselves. Each grid square represents 100 square meters, and has a letter and number to correspond with each grid square e.g. H5 or L6 (letters correlate with columns, whereas numbers correlate with rows.I would like to analyse differences in space use between three different periods of time, to answer questions such as do the animals move around more in certain periods, or are more restricted in their space use in other periods. Please can someone give me any indication of how to go about this? I have looked into spatial analysis in rstudio but haven't come across anything that doesn't use official maps or location co-ordinates. I've not done this type of analysis before so any help would be greatly appreciated! Thanks so much.

Is the below mentioned problem related to travelling salesman problem

I came across this problem, and the first thing that comes to my mind is use TSP.
A person is visiting a new country which has several states. Each state has cities connected via bidirectional roads.
States are divided into cities such that for any two cities A and B,if it is possible to go from A to B by a road and then return to A,A and B belong to the same state.
furthemore,everytime a person enters a new state, you need to pay a cost of 1 $.For travelling on roads that belong to same state there is no cost.
Given an image where cities are represented by colored dots and roads by straight lines, what is the minimum cost a person needs to pay so that he visits every city in every state.
For the image part, I think we can convert it to a graph by using some online library(recommendations on how to do this will be appreciated).
Also, if anyone could give me some ideas/suggestions on how to go about solving the problem, or if they have seen something similar, would be appreciated.
Enclosed are some images that illustrate the graph
I also tried using opencv flood fill to compute the results as mentioned in the comments but it seems I am getting the incorrect result.
import cv2
import numpy as np
img=cv2.imread('graph1.png',cv2.IMREAD_GRAYSCALE)
M,N=img.shape
n_objects=0
for i in range(M):
for j in range(N):
if img[i,j]==255:
n_objects+=1
cv2.floodFill(img,None,(j,i),n_objects)
print(n_objects)
for the first image,expected output is 6,but this returns 3 as the result.Any ideas what can be done to improve the result
The entire prosa about cities etc. is just a red herring. It's not even a graph problem.
It's a basic flooding algorithm on the image which you need:
N = 0
While any pixel != White
Flood with white from pixel
N++
If N > 1
Return N - 1
Else
Return 0
Effectively you only count the number of connected regions which don't correspond to the background color.

A large amount of points to create separate polygons (ArcGIS/QGIS)

Visual example of the data
I used a drone to create a DOF of a small area. During the flight, it takes a photo every 20sh seconds (40sh meters of a flight). I have created a CSV file, which I transferred to a point shapefile. In total, I made with drone 10 so-called "missions", each with 100-200 points which are "shaped" as squares on the map. What I want now is to create a polygon shapefile from the point shapefile.
Because those points sometimes overlap, I cannot use the "Aggregate Points" task, as it's only distance-based. I want to make polygons automatically, using some kind of script. What could help is the fact that a maximum time between two points (AKA photos taken) is 10-20 seconds, so if the time distance is over 3 minutes, it's another "mission". Can you help with such a script, that would quickly and automatically create as many polygons as there are missions?
Okay, I think I understand what you are trying to accomplish. Since no one replied I am going to give it a quick shot, so you have something to try.
I think the best strategy would be to:
Clustering algorithm: Try running a Clustering algorithm such as DBSCAN around the timestamp dimension to classify them based on time groups, instead of the distance (since, as you said, distance based separation is not enough to properly identify and separate the points). After which, you should have all the points classified between different groups with a column group id. Maximum distance parameter in the algorithm should be around 20 seconds steps, or even a minute (since you said each mission was separated at least about 3 minutes apart).
Feature based Polygon to point: At that point, then you run your generic Polygon_from_points(...) function that transforms these clustered points to polygons shapes based on a specific discriminant feature (which in your case is going to be each group id).
How does this work?: This would properly separate the groups first (time-based) and then you should be able to find a generic point to polygon based on a feature (Arcgis should have some).
I dont have an example dataset, nor any code written, but based on what you described I think it would work, hope it helps.

Compare Survey Results Across Regions

I have results from a survey of nurse practitioners asking to what degree (Likert scale, values from 1-5) they feel certain barriers prevent them from adequate practice (i.e. time constraint, location restrictions, etc.). They were also asked to locate where in the state they practice (fill in a bubble). I was wondering if there was a way to code a picture of a U.S. state (say Texas) and superimpose the survey results onto the map by region?
For example: Say one nurse indicated a 1 for feeling time constrained, and she was from the Southern region of Texas. Then, I wold like to show that, out of say a sample of 100, that 1% who responded with a value of 1 came from the Southern region, and have that appear on a map of Texas. Does that make sense?

Finding a quantity of anything between two points in space

I'm currently working towards a 3D model of this, but I thought I would start with 2D. Basically, I have a grid of longitude and latitude with NO2 concentrations across it. What I want to produce, at least for now, is a total amount of Nitrogen Dioxide between two points. Like so:
2DGrid
Basically, These two points are at different lats and lons and as I stated I want to find the amount of something between them. The tricky thing to me is that the model data I'm working with is gridded so I need to be able to account for the amount of something along a line at the lat and lons at which that line cuts through said grid.
Another approach, and maybe a better one for my purposes, could be visualized like this:3DGrid
Ultimately, I'd like to be able to create a program (within any language honestly) that could find the amount of "something" between two points in a 3D grid. If you would like specfics, the bottom altitude is the surface, the top grid is the top of the atmosphere. The bottom point is a measurement device looking at the sun during a certain time of day (and therefore having a certain zenith and azimuth angle). I want to find the NO2 between that measurement device and the "top of the atmosphere" which in my grid is just the top altitude level (of which there are 25).
I'm rather new to coding, stack exchange, and even the subject matter I'm working with so the sparse code I've made might end up creating more clutter than purely asking the question and seeing what methods/code you might suggest?
Hopefully my question is beneficial!
Best,
Taylor
To traverse all touched cells, you can use Amanatides-Woo algorithm. It is suitable both for 2D and for 3D case.
Implementation clues
To account for quantity used from every cell, you can apply some model. For example, calculate path length inside cell (as difference of enter and exit coordinates) and divide by normalizing factor to get cell weight (for example, byCellSize*Sqrt(3) for 3D case as diagonal length).

Resources