Points not showing in Map using TimeStampedGeojson Folium Plugin - folium

I followed https://nbviewer.jupyter.org/github/python-visualization/folium/blob/master/examples/Plugins.ipynb to create my own map using TimeStampedGeojson folium Plugin, Time slider is working but points aren't getting displayed on map. I have using pune city coordinates , the aim was to display multipoint coordinates with changing icon and popup with timeslider functionality over a month.
points = [
{
'time': '2019-09-01',
'popup': '<h1>address1</h1>',
'coordinates': [18.528387, 73.874251]
},
{
'time': '2019-09-02',
'popup': '<h1>address1</h1>',
'coordinates': [18.456863, 73.801601]
},
{
'time': '2019-09-03',
'popup':'<h1>address1</h1>',
'coordinates': [18.527615, 73.872384]
},
{
'time': '2019-09-04',
'popup': '<h1>address1</h1>',
'coordinates': [18.528387, 73.874251]},
{
'time': '2019-09-05',
'popup': '<h1>address1</h1>',
'coordinates': [18.456863, 73.801601]}]
features = [
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': point['coordinates'],
},
'properties': {
'time': point['time'],
'popup': point['popup']
}
} for point in points]
features.append(
{
'type': 'Feature',
'geometry': {
'type': 'LineString',
'coordinates':[
[18.528387, 73.874251],
[18.456863, 73.801601],
[18.527615, 73.872384],
[18.528387, 73.874251],
[18.456863, 73.801601]
] ,
},
'properties': {
'popup': 'Current address',
'times': [
'2019-09-01',
'2019-09-02',
'2019-09-03',
'2019-09-04',
'2019-09-05'
]
}
})
m = folium.Map(
location=[18.5204,73.8567],
tiles='cartodbpositron',
zoom_start=10,)
plugins.TimestampedGeoJson(
{
'type': 'FeatureCollection',
'features': features
},
auto_play=False,
loop=False,
#max_speed=1,
loop_button=True,
date_options='YYYY/MM/DD',
#time_slider_drag_update=True,
duration='P2D').add_to(m)
This is the output of code in jupyter

The locations are getting rendered on the map, try zooming out the map's current view. I suspect the issue is with incorrect order of lat/long positions given inside your coordinates var.

Related

How to convert pandas dataframe to a dictionary list dictionary?

I have a movie link dataframe and I want it to look like this:
{
'tt0051744': [
{
'title': 'Torrent',
'infoHash': '9f86563ce2ed86bbfedd5d3e9f4e55aedd660960'
}
],
'tt1254207': [
{
'title': 'HTTP URL',
'url': 'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4'
}
],
'tt0137523': [
{
'title': 'External URL',
'externalUrl': 'https://www.netflix.com/watch/26004747'
}
]
}
I tried to use:
df.to_json('filmes.json', orient='records')
But it did not work.

unable to use create_job function using s3 control for batch operations

I am unable to understand how to fill in the fields inside the create_job function. (specifically manifest parameter). I would really appreciate if someone would give a real time example for the create_job function as i could not find it on the internet.
What i need to do is to add tags to multiple objects at once.
code which i have written and understood till now is below:
client = boto3.client('s3control')
response = client.create_job(
AccountId='682283364620 ',
Operation={
'S3PutObjectTagging': {
'TagSet': [
{
'Key': 'naturalnumber',
'Value': 'yo'
},
]
}
},
Report={
'Bucket': 'shivam1052061',
'Format': 'Report_CSV_20180820',
'Enabled': True,
'Prefix': 'string',
'ReportScope': 'AllTasks'
},
ClientRequestToken='',
Manifest={
'Spec': {
'Format': 'S3BatchOperations_CSV_20180820',
'Fields': [
'Ignore'|'Bucket'|'Key'|'VersionId',
]
},
'Location': {
'ObjectArn': 'string',
'ObjectVersionId': 'string',
'ETag': 'string'
}
},
Description='string',
Priority=123,
RoleArn='string'
)
You can use the manifest files that S3 Inventory with the Object ARN an ETag
Manifest={
'Spec': {
'Format': 'S3InventoryReport_CSV_20161130'
},
'Location': {
'ObjectArn': 'arn:aws:s3:::bucket/report/2020-08-17T00-00Z/manifest.json',
'ETag': 'xxxxxxxxx'
}
}

Using if/then/else schema validation conditional on values in other json objects

I'm trying to use if/then/else to use three different schemas for an object, but based on the value of a JSON field outside of that object. I've only seen example of people making their conditionals based on fields within the same object.
Here's what I've tried:
schema: {
'MyOtherObject': {
'$id': '#/properties/MyOtherObject',
'type': 'object',
'additionalProperties': false,
'title': 'The MyOtherObject Schema',
'required': [
'PaymentMethod'
],
'properties': {
'PaymentMethod': {
'$id': '#/properties/Deal/properties/PaymentMethod',
'type': 'string',
'title': 'The PaymentMethod Schema',
'default': '',
'examples': [
'Cash'
],
'pattern': '^(.*)$'
},
...
},
'MyConditionalSchemaObject': {
'$id': '#/properties/MyConditionalSchemaObject',
'type': 'object',
'additionalProperties': false,
'title': 'The MyConditionalSchemaObject Schema',
'if': {
// Trying to get at the value above but don't know how... my schema validations still failing
'2/MyOtherObject/properties/PaymentMethod' : { 'const': 'Cash' }
},
'then': {
'required': [
'PaymentStartDate'
],
'properties': {
'BankName': {
'$id': '#/properties/Financing/properties/BankName',
'type': ['string', 'null'],
'title': 'The Bankname Schema',
'default': '',
'examples': [
'Capital One Auto Finance'
],
...
}
}
I would expect that this code would check the value of the PaymentMethod field in the MyOtherObject json object and then use the schema based on passing the conditional check (if it equals Cash), but I'm still getting schema validation errors saying, Should not be additional properties 'BankName', implying that the schema in the "then" block is not being used for validation.

create a table with a column type RECORD

I'm using big query and i want to create a job which populates a table with a "record" type columns.
The data will be populated by a query - so how can i write a query which returns "record" type columns.
Thanks!
Somehow option proposed by Pentium10 never worked for me in GBQ UI or API Explorer.
I might be missing something
Meantime, the workaround I found is as in below example
SELECT location.state, location.city FROM JS(
( // input table
SELECT NEST(CONCAT(state, ',', city)) AS locations
FROM (
SELECT state, city FROM
(SELECT 'florida' AS state, 'miami' AS city),
(SELECT 'california' AS state, 'la' AS city),
(SELECT 'romania' AS state, 'transylvania' AS city)
)
),
locations, // input columns
"[ // output schema
{'name': 'location', 'type': 'RECORD',
'mode': 'REPEATED',
'fields': [
{'name': 'state', 'type': 'STRING'},
{'name': 'city', 'type': 'STRING'}
]
}
]",
"function(row, emit){ // function
for (var i = 0; i < row.locations.length; i++) {
var c = [];
x = row.locations[i].split(',');
t = {state:x[0], city:x[1]}
c.push(t);
emit({location: c});
};
}"
)
Please note:
you should set destination table with Allow Large Results and unchecked Flatten Results
Result from output table is (in JSON Mode)
[
{
"location": [
{
"state": "california",
"city": "la"
}
]
},
{
"location": [
{
"state": "florida",
"city": "miami"
}
]
},
{
"location": [
{
"state": "romania",
"city": "transylvania"
}
]
}
]
Added to address some issue #AdiCohen has with his real example that
he showed in his recent comments:
Q: my query has other columns besides the record column, but when i ran
the query, they return as null. how can i create a table with both of
the types?
SELECT amount, currency, location.state, location.city FROM JS(
( // input table
SELECT NEST(CONCAT(state, ',', city)) AS locations,
SUM(amount) AS amount, MAX(currency) as currency
FROM (
SELECT state, city, amount, currency, ROW_NUMBER() OVER() as grp FROM
(SELECT 'florida' AS state, 'miami' AS city, 'coins' AS currency, 40 AS amount),
(SELECT 'california' AS state, 'la' AS city, 'coins' AS currency, 40 AS amount),
(SELECT 'romania' AS state, 'transylvania' AS city,'coins' AS currency, 40 AS amount)
) GROUP BY grp
),
amount, currency, locations, // input columns
"[ // output schema
{'name': 'location', 'type': 'RECORD', 'mode': 'REPEATED',
'fields': [
{'name': 'state', 'type': 'STRING'},
{'name': 'city', 'type': 'STRING'}
] },
{ 'name': 'amount', 'type': 'INTEGER'},
{ 'name': 'currency', 'type': 'STRING'}
]",
"function(row, emit) { // function
for (var i = 0; i < row.locations.length; i++) {
var c = [];
x = row.locations[i].split(',');
t = {state:x[0], city:x[1]}
c.push(t);
emit({amount: row.amount, currency: row.currency, location: c});
};
}"
)
Output here is:
[
{
"amount": "40",
"currency": "coins",
"location_state": "romania",
"location_city": "transylvania"
},
{
"amount": "40",
"currency": "coins",
"location_state": "florida",
"location_city": "miami"
},
{
"amount": "40",
"currency": "coins",
"location_state": "california",
"location_city": "la"
}
]
You need to use the dot notation to reflect the output as a RECORD example query:
select
'florida' as country.state,
'SFO' as country.city;
In this example country is the record and state|city are fields in the record.

Can I customize the tooltip text in a Google Geochart chart?

Below is the code I'm using, based on a how to I found in Google's documentation, but I'm not sure if it applies to the Geochart, if I'm doing it right, or if there is some other way to do it for a Geochart.
This code works fine if I don't include the tooltip column. When I do, I get the error "Incompatible data table: Error: Table contains more columns than expected (Expecting 2 columns)," displayed where the Geochart should be.
This question addresses the same issue, but not specifically for a Geochart.
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load( 'visualization', '1', { 'packages': ['geochart'] } );
google.setOnLoadCallback( drawRegionsMap );
function drawRegionsMap()
{
var data = google.visualization.arrayToDataTable([
[ 'State', 'Relevance', {type: 'string', role: 'tooltip'} ],
[ 'Alabama', 3, 'tooltip test text' ],
[ 'Arizona', 1, 'tooltip test text' ],
]);
var options =
{
region: 'US',
resolution: 'provinces',
};
var chart = new google.visualization.GeoChart( document.getElementById( 'chart_div' ) );
chart.draw( data, options );
};
</script>
I was able to include the text i wanted in the tooltip, including the values this way:
var data = new google.visualization.DataTable();
data.addColumn('string', 'Country'); // Implicit domain label col.
data.addColumn('number', 'Value'); // Implicit series 1 data col.
data.addColumn({type:'string', role:'tooltip'}); //
data.addRows([
[{v:"US",f:"United States of America"},1,"21% of Visits"],
[{v:"GB",f:"United Kingdom"},2,"7% of visits"],
[{v:"DE",f:"Germany"},3,"6% of visits"],
[{v:"FR",f:"France"},4,"5% of visits"],
[{v:"ES",f:"Spain"},5,"5% of visits"],
[{v:"CA",f:"Canada"},6,"4% of visits"],
[{v:"IT",f:"Italy"},7,"4% of visits"],
[{v:"NL",f:"The Netherlands"},8,"4% of visits"],
[{v:"BR",f:"Brazil"},9,"4% of visits"],
[{v:"TR",f:"Turkey"},10,"3% of visits"],
[{v:"IN",f:"India"},11,"3% of visits"],
[{v:"RU",f:"Russia"},12,"3% of visits"],
[{v:"AU",f:"Australia"},13,"2% of visits"],
]);
This way, for example "United States of America" would be line 1 of the tooltip, and "21% of visits" would be the second line. With this format I can include whatever text I want in the tooltip, in both lines.
In order to customize the tooltip to use html including new line / images please check this example:
http://jsfiddle.net/SD4KA/
google.load('visualization', '1.1', {packages: ['geochart'], callback: drawVisualization});
function drawVisualization() {
var data = google.visualization.arrayToDataTable([
['Country', 'Value', {role: 'tooltip', p:{html:true}}],
['Russia', 5, 'Hello world<br>test'],
['US', 20, '<img src="https://www.google.com/images/srpr/logo6w.png"/>']]);
var chart = new google.visualization.GeoChart(document.getElementById('visualization'));
chart.draw(data, {
width: 800,
height: 600,
tooltip: {
isHtml: true
}
});
}
Since v1.1 geochart supports html for tooltips
There are three alternatives presented in this thread
Set the formatted value of your data points manually (using the #setFormattedValue() DataTable method)
Use one of the formatters on a DataTable column
Include a 'tooltip' role column in the DataTable
I've personally used first one, and with your example should be like
var data = google.visualization.arrayToDataTable([
[ 'State', 'Relevance' ],
[ 'Alabama', { v: 3, f: 'tooltip test text' } ],
[ 'Arizona', { v: 1, f: 'tooltip test text' } ],
]);
I ran into a similar issue for a scatter chart. I had to use arrayToDataTable to get the data into the chart as opposed to DataTable() and addColumn() as suggested in other answers.
In order to get it to work, you make the call to arrrayToDataTable() as you are currently doing and saving to the variable data.
Then, you need to specify which column you want to be treated as a tooltip (and you must specify which columns should be plotted as well). In the following example, columns 0 and 1 contain the plot data, and column 2 contains the tooltip strings.
var view = new google.visualization.DataView(data);
view.setColumns([0, 1, {sourceColumn: 2,role:'tooltip'}]);
Finally, you must make the call to draw with the view variable rather than with the data variable:
chart.draw(view, options);
It seems like it is impossible to format the text the exact way I was attempting to with the GeoChart tool. Below is the solution I finally came up with and the rendered map:
Rendered Map with Tooltip View
PHP & JavaScript Code
<!-- generate geo map -->
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load( 'visualization', '1', { 'packages': ['geochart'] } );
google.setOnLoadCallback( drawRegionsMap );
function drawRegionsMap()
{
// create data table
var data = google.visualization.arrayToDataTable([
<?php echo $data_table; ?>
]);
// create chart object
var chart = new google.visualization.GeoChart(
document.getElementById( 'chart_div' )
);
// defines the data for the tooltip
var formatter = new google.visualization.PatternFormat('{0}');
formatter.format( data, [0,1], 1 );
var formatter = new google.visualization.PatternFormat('{2}');
formatter.format( data, [0,1,2], 0 );
// defines the data for the chart values
var view = new google.visualization.DataView(data);
view.setColumns([0, 1]);
// set options for this chart
var options =
{
width: <?php echo $width; ?>,
region: 'US',
resolution: 'provinces',
colorAxis: { colors: ['#abdfab', '#006600'] },
legend: 'none'
};
// draw chart
chart.draw( view, options );
};
</script>
<div id="chart_div" style="width: <?php echo $width; ?>px; height: <?php echo $height; ?>px;"></div>
Rendered HTML
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load( 'visualization', '1', { 'packages': ['geochart'] } );
google.setOnLoadCallback( drawRegionsMap );
function drawRegionsMap()
{
// create data table
var data = google.visualization.arrayToDataTable([
[ 'State', 'in', 'String' ],
[ 'Arizona', 2, 'Has Facility, Sells Direct' ],
[ 'California', 4, 'Has Facility, Has Distributor, Sells Direct' ],
[ 'Colorado', 1, 'Sells Direct' ],
[ 'Florida', 1, 'Has Distributor' ],
[ 'Georgia', 1, 'Has Distributor' ],
[ 'Idaho', 1, 'Sells Direct' ],
[ 'Illinois', 1, 'Has Distributor' ],
[ 'Indiana', 1, 'Has Distributor' ],
[ 'Iowa', 1, 'Has Distributor' ],
[ 'Kansas', 1, 'Has Distributor' ],
[ 'Kentucky', 1, 'Has Distributor' ],
[ 'Louisiana', 1, 'Has Distributor' ],
[ 'Maryland', 2, 'Has Distributor' ],
[ 'Montana', 1, 'Sells Direct' ],
[ 'Nevada', 2, 'Has Facility, Sells Direct' ],
[ 'New Mexico', 2, 'Has Facility, Sells Direct' ],
[ 'North Carolina', 1, 'Has Distributor' ],
[ 'North Dakota', 1, 'Has Distributor' ],
[ 'Oklahoma', 1, 'Sells Direct' ],
[ 'Oregon', 1, 'Sells Direct' ],
[ 'Pennsylvania', 1, 'Has Distributor' ],
[ 'South Carolina', 1, 'Has Distributor' ],
[ 'Tennessee', 1, 'Has Distributor' ],
[ 'Texas', 1, 'Has Distributor' ],
[ 'Utah', 2, 'Has Facility, Sells Direct' ],
[ 'Washington', 1, 'Sells Direct' ],
[ 'Wyoming', 1, 'Sells Direct' ], ]);
// create chart object
var chart = new google.visualization.GeoChart(
document.getElementById( 'chart_div' )
);
// defines the data for the tooltip
var formatter = new google.visualization.PatternFormat('{0}');
formatter.format( data, [0,1], 1 );
var formatter = new google.visualization.PatternFormat('{2}');
formatter.format( data, [0,1,2], 0 );
// defines the data for the chart values
var view = new google.visualization.DataView(data);
view.setColumns([0, 1]);
// set options for this chart
var options =
{
width: 286,
region: 'US',
resolution: 'provinces',
colorAxis: { colors: ['#abdfab', '#006600'] },
legend: 'none'
};
// draw chart
chart.draw( view, options );
};
</script>
<div id="chart_div" style="width: 286px; height: 180px;"></div>