Polyline issue for satellite track - osmdroid

I'm using osmdroid to draw a polyline on an offline map
Polyline p = new Polyline(map);
p.setColor(Color.RED);
p.setWidth(1f);
p.setGeodesic(true);
p.setPoints(mypointslist);
Here is the problem:
When my points are:
1. Lat 45 Lon 170
2. Lat 45 Lon -160
3. Lat 45 Lon -80
4. Lat 45 Lon 0
5. Lat 45 Lon 160
6. Lat 60 Lon 170
7. Lat 60 Lon -160
8. Lat 60 Lon -80
The polyline is always a ring...and when I pan around the line it change
The track is not displayed open.
It seems that the start point is always connected with the end point
Someone has an hint that points me in the correct way ?
Thanks all....

Related

Pandas and reg ex, decompoising text and numbers into several columns with headings

I have a dataframe with a column containing:
1 Tile 1 up Red 2146 (75) Green 1671 (75)
The numbers 1 can be upto 10
up can be also be down
The 2146 and 1671 can be any digit upto 9999
Whats the best way to break out each of these into separate columns without using split. I was looking at regex but not sure how to handle this (especially the white spaces). I liked the idea of putting the new column names in too and started with
Pixel.str.extract(r'(?P<num1>\d)(?P<text>[Tile])(?P<Tile>\d)')
Thanks for any help
To avoid an overly complicated regex pattern, perhaps you can use str.extractall to get all numbers, and then concat to your current df. For up or down, use str.findall:
df = pd.DataFrame({"title":["1 Tile 1 up Red 2146 (75) Green 1671 (75)",
"10 Tile 10 down Red 9999 (75) Green 9999 (75)"]})
df = pd.concat([df, df["title"].str.extractall(r'(\d+)').unstack().loc[:,0]], axis=1)
df["direction"] = df["title"].str.findall(r"\bup\b|\bdown\b").str[0]
print (df)
#
title 0 1 2 3 4 5 direction
0 1 Tile 1 up Red 2146 (75) Green 1671 (75) 1 1 2146 75 1671 75 up
1 10 Tile 10 down Red 9999 (75) Green 9999 (75) 10 10 9999 75 9999 75 down

How to measure the length (in pixel) for each pole in an image

I want to measure the height and width of each individual pole in pixel.
But because the poles are not always stand straight, but i need the height of pole from the horizontal ground. Can anyone guide me how to handle this?
Note: I might need to get the angle it has slanted later on. Not sure I can ask so many question in here. But greatly appreciate if someone can help.
The image sample i have is at below link:
This should give you a good idea how to do it:
#!/usr/local/bin/python3
import cv2
# Open image in greyscale mode
img = cv2.imread('poles.png',cv2.IMREAD_GRAYSCALE)
# Threshold image to pure black and white AND INVERT because findContours looks for WHITE objects on black background
_, thresh = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV)
# Find contours
_, contours, _ = cv2.findContours(thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
# Print the contours
for c in contours:
x,y,w,h = cv2.boundingRect(c)
print(x,y,w,h)
The output is this, where each line corresponds to one vertical bar in your image:
841 334 134 154 <--- bar 6 is 154 pixels tall
190 148 93 340 <--- bar 2 is 340 pixels tall
502 79 93 409 <--- bar 4 is 409 pixels tall
633 55 169 433 <--- bar 5 is 433 pixels tall
1009 48 93 440 <--- bar 7 is 490 pixels tall
348 48 93 440 <--- bar 3 is 440 pixels tall
46 46 93 442 <--- bar 1 is 442 pixels tall (leftmost bar)
The first column is the distance from the left edge of the image and the last column is the height of the bar in pixels.
As you seem unsure about whether you want to do this in Python or C++, you may prefer not write any code at all - in which case you can simply use ImageMagick which is included in most Linux distros and is available for macOS and Windows.
Basically, you use "Connected Component" analysis by typing this into the Terminal:
convert poles.png -colorspace gray -threshold 50% \
-define connected-components:verbose=true \
-connected-components 8 null:
Output
Objects (id: bounding-box centroid area mean-color):
0: 1270x488+0+0 697.8,216.0 372566 srgb(255,255,255)
1: 93x442+46+46 92.0,266.5 41106 srgb(0,0,0)
2: 93x440+348+48 394.0,267.5 40920 srgb(0,0,0)
3: 93x440+1009+48 1055.0,267.5 40920 srgb(0,0,0)
4: 169x433+633+55 717.3,271.0 40269 srgb(0,0,0)
5: 93x409+502+79 548.0,283.0 38037 srgb(0,0,0)
6: 93x340+190+148 236.0,317.5 31620 srgb(0,0,0)
7: 134x154+841+334 907.4,410.5 14322 srgb(0,0,0)
That gives you a header line which tells you what all the fields are, then a line for each of the blobs it found in the image. Disregard the first one because that is the white background - you can see that from the last field which is rgb(255,255,255).
So, if we look at the last line, it is a blob that is 134 pixels wide and 154 pixels tall, starting at x=841 and y=334 from the top-left corner, i.e. it corresponds to the first contour that OpenCV found.

How can obtain middle number with grid/step in Python

I want to know how obtain with python 2.7 the middle number in a range like but with a predefined grid per example of 40 per 40 (multiple of 40):
0, 600 the number will be 320 and not 300 because 300 is not a multiple of 40...
0, 300 the number will be 160 and not 150 because 150 is not a multiple of 40...
Any help will be appreciated...
EDIT
i want a function or something like that not myself calculating...
something like this?
def mean_mod(a, b, md=40):
return md * ( ((a+b)//2) // md )
print(mean_mod(0, 600))
print(mean_mod(0, 300))
output:
280
120
(rounds down...)

Pandas quantile failing with NaN's present

I've encountered an interesting situation while calculating the inter-quartile range. Assuming we have a dataframe such as:
import pandas as pd
index=pd.date_range('2014 01 01',periods=10,freq='D')
data=pd.np.random.randint(0,100,(10,5))
data = pd.DataFrame(index=index,data=data)
data
Out[90]:
0 1 2 3 4
2014-01-01 33 31 82 3 26
2014-01-02 46 59 0 34 48
2014-01-03 71 2 56 67 54
2014-01-04 90 18 71 12 2
2014-01-05 71 53 5 56 65
2014-01-06 42 78 34 54 40
2014-01-07 80 5 76 12 90
2014-01-08 60 90 84 55 78
2014-01-09 33 11 66 90 8
2014-01-10 40 8 35 36 98
# test for q1 values (this works)
data.quantile(0.25)
Out[111]:
0 40.50
1 8.75
2 34.25
3 17.50
4 29.50
# break it by inserting row of nans
data.iloc[-1] = pd.np.NaN
data.quantile(0.25)
Out[115]:
0 42
1 11
2 34
3 12
4 26
The first quartile can be calculated by taking the median of values in the dataframe that fall below the overall median, so we can see what data.quantile(0.25) should have yielded. e.g.
med = data.median()
q1 = data[data<med].median()
q1
Out[119]:
0 37.5
1 8.0
2 19.5
3 12.0
4 17.0
It seems that quantile is failing to provide an appropriate representation of q1 etc. since it is not doing a good job of handling the NaN values (i.e. it works without NaNs, but not with NaNs).
I thought this may not be a "NaN" issue, rather it might be quantile failing to handle even-numbered data sets (i.e. where the median must be calculated as the mean of the two central numbers). However, after testing with dataframes with both even and odd-numbers of rows I saw that quantile handled these situations properly. The problem seems to arise only when NaN values are present in the dataframe.
I would like to use quntile to calculate the rolling q1/q3 values in my dataframe, however, this will not work with NaN's present. Can anyone provide a solution to this issue?
Internally, quantile uses numpy.percentile over the non-null values. When you change the last row of data to NaNs you're essentially left with an array array([ 33., 46., 71., 90., 71., 42., 80., 60., 33.]) in the first column
Calculating np.percentile(array([ 33., 46., 71., 90., 71., 42., 80., 60., 33.]) gives 42.
From the docstring:
Given a vector V of length N, the qth percentile of V is the qth ranked
value in a sorted copy of V. A weighted average of the two nearest
neighbors is used if the normalized ranking does not match q exactly.
The same as the median if q=50, the same as the minimum if q=0
and the same as the maximum if q=100.

Arranging coordinates into clockwise order

I have 9 screen coordinates, each representing one of 9 positions. From the top right, I want that position to start as the 1st position, and the following clockwise coordinates to represent the 2nd, 3rd, 4th and so on, up until the 9th, which would be the top left coordinate.
Would anybody here be able to come up with some sort of mathematical means of determining which of the 9 coordinates is in which position? They're all relative to each other, and will always be THAT relative to each other.
Example coordinates could be:
(x,y)
X Y
663 382
543 454
303 454
183 382
418 459
543 209
303 209
653 259
183 259
Plotting into an image something like:
Would anybody have any ideas? I simply want some form of programmatic way of listing these coordinates in clockwise order...
Find the center of the "circle," i.e., the average X and average Y
Shift the X and Y values so all are relative to the new center.
Convert to polar coordinates and sort by angle.
Assuming I understand you correctly, I would just do something like
newPosition = (originalPosition + # of rotations) mod 8
Where I am assuming that the first position is 0, and that you can only make the things jump clockwise by integer increments (hence the # of rotations)