how to preserve the extent of a spatial object (e.g. SpatialPoints) after "over()" - spatial

For example, I have two SpatialPoints objects (a, and b). After I use the "over" function:
c<-a[b,]
the extent of c might have a different extent. Is there a way that while doing the selecting, the extent of a (or b) can be preserved?
thanks!

please try
a[b,,drop=FALSE]
it should leave the bounding box of a in tact.

Related

How to apply filter to image in Swift?

Today I've searched a lot about it, found something but I'm still confusing.
For example, I have the next filter:
The result need to be:
How can I apply it to my image?
I know how to apply such type of effects as: PhotoEffectNoir, or CIPhotoEffectChrome, but how can I apply this matrix(or I do not know how to call it) to my UIImage?
Can anyone help me with a little example?
This will be just a hint of an answer for now; I'll come back with more details as I have time.
Your first image is a color lookup table (aka CLUT), sometimes also called a color cube. It's a representation of a three-dimensional array where the x, y, and z coordinates are the r, g, and b components of an input color, and the value at a given xyz coordinate is the output color for that particular rgb input. (Because it's being stored in a 2D image, the 3D table is split into slices.)
You can use a CLUT for filtering in Core Image with the CIColorCube filter. The trick to it is in converting your CLUT image to the right format to pass as a parameter to that filter.
You can find some examples of constructing (rather than converting an image to) a color cube in Apple's docs and elsewhere on SO.

spatial set operations in Apache Spark

Has anyone been able to do spatial operations with #ApacheSpark? e.g. intersection of two sets that contain line segments?
I would like to intersect two sets of lines.
Here is a 1-dimensional example:
The two sets are:
A = {(1,4), (5,9), (10,17),(18,20)}
B = {(2,5), (6,9), (10,15),(16,20)}
The result intersection would be:
intersection(A,B) = {(1,1), (2,4), (5,5), (6,9), (10,15), (16,17), (18,20)}
A few more details:
- sets have ~3 million items
- the lines in a set cover the entire range
Thanks.
One approach to parallelize this would be to create a grid of some size, and group line segments by the grids they belong to.
So for a grid with sizes n, you could flatMap pairs of coordinates (segments of line segments), to create (gridId, ( (x,y), (x,y) )) key-value pairs.
The segment (1,3), (5,9) would be mapped to ( (1,1), ((1,3),(5,9) ) for a grid size 10 - that line segment only exists in grid "slot" 1,1 (the grid from 0-10,0-10). If you chose a smaller grid size, the line segment would be flatmapped to multiple key-value pairs, one for each grid-slot it belongs to.
Having done that, you can groupByKey, and for each group, calculation intersections as normal.
It wouldn't exactly be the most efficient way of doing things, especially if you've got long line segments spanning multiple grid "slots", but it's a simple way of splitting the problem into subproblems that'll fit in memory.
You could solve this with a full cartesian join of the two RDDs, but this would become incredibly slow at large scale. If your problem is smallish, sure, this is an easy and cheap approach. Just emit the overlap, if any, between every pair in the join.
To do better, I imagine that you can solve this by sorting the sets by start point, and then walking through both at the same time, matching one's current interval versus another and emitting overlaps. Details left to the reader.
You can almost solve this by first mapping each tuple (x,y) in A to something like ((x,y),'A') or something, and the same for B, and then taking the union and sortBy the x values. Then you can mapPartitions to encounter a stream of labeled segments and implement your algorithm.
This doesn't quite work though since you would miss overlaps between values at the ends of partitions. I can't think of a good simple way to take care of that off the top of my head.

How can I use bwlabel or regionprops to extract set of pixels of each label?

I'm following this tutorial
The goal is to be able to spit out either:
a. the center of each labeled object
b. all pixels associated with each labeled object
in a way that I have an array of either 'a.' for each object, or 'b.' for each object
I'm really not sure how to go about this. Are there matlabl tools to help extract these set of pixels or centers - per - label?
Update
I did manage to circle 80% of what I wanted using reigionprops, however it doesn't capture label precisely, just sets a circle around them while capturing the background as well, is that really unavoidable? I'm just not sure how to access the set of pixel per each circled item.
r=regionprops(L, 'All'); imshow(imagergb); areas={r.Area}; Bboxes={r.BoundingBox};
for k=2:numel(r)
if areas{k}>50 && areas{k} < 1100
rectangle('Position',Bboxes{k}, 'LineWidth',1, 'EdgeColor','b', 'Curvature', [1 1]);
end
end
So what I'm trying to do is for example.
I thought it might just be
r = regionprops(L, 'PixelIdxList')
then
element1 = r(1).PixelIdxList
but couldn't figure out how to get the position of each pixel
I also tried
Z= bwlabel(L);
but imshow(Z==1) spits out all labels and imshow(Z==2) spits out background, all labels and background. couldn't test bwlabeln since I'm not exactly sure what to enter for r and c arguments.
Using regionprops(L, 'PixelIdxList') is correct. It gives you lists of pixel indices for each label. You can then convert them to [x,y] coordinates using (for the first label, for example)
[y,x] = ind2sub(size(L), r(1).PixelIdxList)
You can get label centers by using regionprops(L, 'Centroid'). This already gives you [x,y] coordinates for each label. Note that these are subpixel coordinates, so you may need to round them if you want to use them as indices.

Boardgame-Map with crossroads etc

I have a little logical problem over here.
As the title says, I try to build a boardgame as a computer-program (maybe with internet-support, but thats another story)
As for now, I have a map, which has some crossroads in it, hence I cannot simply define the fields as '1, 2, 3, 4, ...' because if there is a crossroad at field 10, I would have more than one field which has to be labeled 11 (Because then there is a field left and right of field 10, for example.)
So the problem is, if I cannot define the Board in numbers then I cannot simply get the possible positions a player can take when he rolls 2d6-dices with calculating 'Field-Nr. + RandomRange(1,6) + RandomRange(1,6)'
Does anybody have an idea, how to define a Map like this on another way, where I still can calculate the possible new-fields for Player X with a 2d6-dice-roll?
Thanks in advance.
If i understand well... (i don't thing so) this might help you. Just use dynamic arrays for your boardgame field and change your actions after the dimensions x,y .... Look at this "type Name = array of {array of ...} Base type; // Dynamic array"
It sounds like you have a graph of connected vertices. When a player is at a particular vertex of N edges, assuming N < 12, the new Field will be reached from traversing edge number N % ( rand(6) + rand(6) ).
You could also just do rand(12), but that would have an even distribution, unlike 2d6.
Instead of dynamic arrays, I would recommend using a linked-list of records to describe the surrounding cells, and traverse the player's location and possible moves using that linked-list.
First, define a record that describes each cell in your board's playable grid (the cells on the grid can be four-sided like a chessboard, or hexagonal like in Civilization V) ... each cell record should contain info such as coordinates, which players are also in that cell, any rewards/hazards/etc that would affect gameplay, etc. (you get the idea).
Finally, the linked-list joins all of these cells, effectively pointing to any connected cells. That way, all you'd need is the cell location of Player X and calculate possible moves over n amount of cells (determined by the dice roll), traversing the adjoining cells (that don't have hazards, for example).
If all you want is to track the possible roads, you can also use this approach to identify possible paths (instead of cells) Player X can travel on.

Delphi Tchart x and y values in zoomed rectangle

I have a tchart series that contains 5000 points from a data base.
I can zoom in on a particular section of the data with the mouse.
I wish to copy only the x and y values that are visible in the subset to the clipboard (or text file).
I can easiy access the entire series, however I have not been able to figure out how to access only
the data in the zoomed rectangle.
Any help is appreciated.
Thanks in advance
Arthur
The series X index range in the zoomed rectangle is [FirstValueIndex..LastValueIndex].
Note : They are only accessible after the values are displayed.
A value of -1 means that the whole range is to be used. [0..Count-1]
Update :
And if you want to clip on Y values as well, then step through above indexes and check against leftAxis.Minimum and leftAxis.Maximum.
If you can represent any point from the series as a TPoint structure (e.g. with the help of the Point() function) and the view area as a TRect (e.g. using Rect()), you will be able to use the PtInRect() function to test whether the point is within the zoomed rectangle:
if PtInRect(ZoomedRect, ChartPoint) then ...
References:
TPoint
Point()
TRect
Rect()
PtInRect()
This was discussed here. Hope suggestions here are useful for you.

Resources