How to generate a graph file? - dictionary

Is there a way to generate valid graph files like simple-leuven.dot or graphs of other cities available on Rinsim?
We'd like to find a fast way to generate directed cyclic graphs with various geometries.

The Leuven map was downloaded from OpenStreetMap as an XML file and then converted to dot using a script. The code that was used for this has been removed from the main RinSim branch as it is very fragile. You can still find the code in the repository though, see OSM.java in v2.3.3.
A few other city maps have been created using this code and they can be found on this website.

Apparently, the code in OSM.java has been refactored into a project in this github repo osm-to-dot-converter. All you have to do is to create a main method to convert an XML openstreetmap file (.osm). For instance:
public static void main(String[] args) {
OsmConverter myOsmConverter = new OsmConverter();
myOsmConverter.setOutputDir("/home/username/");
myOsmConverter.withOutputName("cityname.dot");
// I am not sure what pruning is used for,
// you can comment out the next line if you do not understand what it is used for
myOsmConverter.withPruner(new RoundAboutPruner(1), new CenterPruner());
// the XML file is to be feed here
myOsmConverter.convert("/home/username/cityname.osm");
}

Related

How to modify the DataLabel fill (using a solid fill color)?

I'm trying to edit the data labels for a chart I'm writing on the slide. I can access the text of the datalabel using the methods available but as of yet the datalabel.fill is not existent. Any workarounds welcome if this is not planned on being added to the library in the future.
I've already gone through the source code in the github (https://github.com/scanny/python-pptx) but the datalabel class only has the font, has_text_frame, position, text_frame, _dLbl, _get_or_add_dLbl, _get_or_add_rich, _get_or_add_tx_rich, _get_or_add_txPr, and _remove_tx_rich methods. No fill or line fill methods is available.
The script I'm running does something similar for cells in a table:
cell.fill.solid()
cell.fill.fore_color.rgb = color_list[((col>0)*1)][i%2]
I'm looking at replicating the functionality on datalabels for chart series, with code that looks like this:
label.fill.solid()
label.fill.rgb = RGBColor(0x9B,0xBB,0x59)
label.fill.alpha = Alpha(.2)
label.line.fill.solid()
label.line.rgb = RGBColor(0xF0,0xF0,0x00)
The expected output xml should put the following for data labels:
<c:spPr>
<a:solidFill>
<a:srgbClr val="9BBB59">
<a:alpha val="80000"/>
</a:srgbClr>
</a:solidFill>
<a:ln>
<a:solidFill>
<a:schemeClr val="F0F000"/>
</a:solidFill>
</a:ln>
</c:spPr>
Actual output is non-existent as there is no method to do this directly.
This feature is not yet implemented, but if it was implemented it would be a .format property on the DataLabel object.
Typically users will work around an API gap like this by adding what we typically call a "workaround function" to the client code that manipulates the underlying XML directly, in this case, to add an <c:spPr> subtree in the right place.
python-pptx can generally get you close as far as a parent element is concerned. In this case, it can get you to the <c:dLbl> element like this:
data_label = chart.series[0].points[0].data_label
dLbl = data_label._dLbl
print(dLbl.xml)
The leading underscore in ._dLbl is your hint that you're getting into internals and if things don't go well it's something you're doing wrong, not an issue to be reported.
The dLbl object is an lxml.etree._Element object and can be manipulated with that API. If you have a search on "python-pptx workaround function" you'll find some examples for how to create new elements and put them where you want them.
The .xml property available on any python-pptx XML element object is handy for inspecting the results along the way. opc-diag can also be handy for inspecting PPTX files generated by PowerPoint or python-pptx for analysis or diagnostic purposes.

how should i access n number of different .mat file in r by setting a proper path?

I have a total of 121 .mat files for some sonar experiment. I want to read each mat file by the iterative way and each iteration I want to access data from one particular mat file and work on corresponding data. I had already done with Matlab code the same thing I am trying in r.
This is my Matlab code
myFolder = 'G:\minor_project\Indrajeet\Data\ExpData\SingleChannel with
Array Steering\16 cell mesh slanting 30 deg';
% Check to make sure that the folder actually exists. Warn user if it doesn't.
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does notexist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
fpath = dir(fullfile( myFolder, '*.mat'));
filenames = fullfile(myFolder, {fpath.name});
Now if you observe carefully fpath variable you will find the first fullfile function takes myFolfer where my path is store and result in following or build full file name including .mat extension.
G:\minor_project\Indrajeet\Data\ExpData\SingleChannel with Array
Steering\16 cell mesh slanting 30 deg\*.mat
then "dir" function use the same folder name to create the list of (in the form of the structure of 121x1 struct which later I am accessing using dot.operator) all data.
Now I am learning the r programming and tried to mimic the same logic which is made in Matlab and initiated as
library(R.matlab)
myFolder = "G:/minor_project/Indrajeet/Data/ExpData/SingleChannel with
Array Steering/16 cell mesh slanting 30 deg";
if(!file.exists(myFolder))
{
print("Error: The following folder does not exist")
}
currently I know the "readMat" function only,is there any functions whcih will work same as fullfile and dir in r?if so,whcih packages this function belongs to

Documenter.jl: #autodocs for specific source files

From Documenter.jl's documentation of #autodocs:
[...], a Pages vector may be included in #autodocs to filter
docstrings based on the source file in which they are defined:
```#autodocs
Modules = [Foo]
Pages = ["a.jl", "b.jl"]
```
However, it also says
Note that page matching is done using the end of the provided strings
and so a.jl will be matched by any source file that ends in a.jl, i.e.
src/a.jl or src/foo/a.jl.
How can I restrict the #autodocs block to specific source files?
My package's source code is organized as
src/
foo/a.jl
foo/b.jl
ignore/a.jl
ignore/b.jl
other.jl
How to make the #autodocs block only consider files src/foo/a.jl and src/foo/b.jl but not src/ignore/a.jl and src/ignore/b.jl?
Unfortunately, Pages = ["foo/a.jl", "foo/b.jl"] didn't do it for me.
Thanks in advance.
x-ref: https://discourse.julialang.org/t/documenter-jl-autodocs-for-specific-source-files/8784
x-ref: https://github.com/JuliaDocs/Documenter.jl/issues/630
Turns out that this is a Windows issue due to absence of normalization of path separators (see linked github issue).
On Linux Pages = ["foo/a.jl", "foo/b.jl"] should work.
On Windows Pages = ["foo\\a.jl", "foo\\b.jl"] should work.
EDIT: joinpath.("foo", ["a.jl", "b.jl"]) should work on any OS.

Can't display Leaflet HTML through R-Shiny (404 error). How to integrate KML file with rMaps or leaflet-shiny?

I'm having some issues displaying an interactive map in R-Shiny that incorporates a KML file. I installed leaflet-plugins and was able to create an HTML file that displays properly by itself in the browser but not within Shiny. This attempt followed an example here - the code is available if you view source.
Because this initial version does not require the HTML itself to change, I attempted to follow the samples here to include the raw HTML in my page but I receive a 404 error with these as well as when I attempted to include it as an iframe within R-Shiny (following this discussion). I then set up an external facing server for both the KML file and the HTML file and got the same result.
I was able to get a map working without the KML file with leaflet-shiny but I'm frankly not sure how to add the KML file and don't see this in the documentation.
Finally, I tried rMaps which does have a "addKML" method, but I can't get it working with various locations of files on my server (
map1 = Leaflet$new()
map1$setView(c(45.5236, -122.675), 13)
map1$tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png")
map1$addKML('http://kml-samples.googlecode.com/svn/trunk/kml/Placemark/placemark.kml')
map1
It works without the $addKML line. It might be worth noting that the tilelayer line on example 1 here also resulted in a blank map.
I actually have some possibly similar issues hosting derived title layers that are still unresolved which is one reason I opted for uses KML layers for this demo version of the application, which is why I tagged networking on here as well. I'm using Digital Ocean.
Thank you for any thoughts or pointers you may have.
I think there may be a small issue in the rMaps library. If you inspect the config.yml file
https://github.com/ramnathv/rCharts/blob/master/inst/libraries/leaflet/config.yml you will see that for
content delevery network (cdn) there is reference to
"http://harrywood.co.uk/maps/examples/leaflet/leaflet-plugins/layer/vector/KML.js". This KML reader is a plugin for leaflet from https://github.com/shramov/leaflet-plugins/blob/master/layer/vector/KML.js. When content is delivered locally:
css: [external/leaflet.css, external/leaflet-rCharts.css, external/legend.css]
jshead:
- external/leaflet.js
- external/leaflet-providers.js
- external/Control.FullScreen.js
there is no reference to this javascript file. We can fix this:
require(yaml)
leafletLib <- file.path(find.package("rMaps"), "libraries", "leaflet")
rMapsConfig <- yaml.load_file(file.path(leafletLib, "config.yml"))
# add a kml library
kmlLib <- readLines("http://harrywood.co.uk/maps/examples/leaflet/leaflet-plugins/layer/vector/KML.js")
write(kmlLib, file.path(leafletLib, "external", "leaflet-kml.js"))
# add the library to config.yml
rMapsConfig$leaflet$jshead <- union(rMapsConfig$leaflet$jshead , "external/leaflet-kml.js")
write(as.yaml(rMapsConfig), file.path(leafletLib, "config.yml"))
Now the config.yml will contain the necessary link to the KML reader and there is a local copy stored now in external/leaflet-kml.js. Our example still wont work however as we will get a Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://kml-samples.googlecode.com/svn/trunk/kml/Placemark/placemark.kml. This can be fixed by moving the resource to the same domain or enabling CORS.
We will need to have this file served locally. We can place it as a temporary measure in the leaflet folder in the rMaps package. When a map is created this folder gets copied to a temporary file:
require(rMaps)
map1 = Leaflet$new()
map1$setView(c(45.5236, -122.675), 13)
map1$tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png")
map1$addKML('leaflet/placemark.kml')
# temp copy http://kml-samples.googlecode.com/svn/trunk/kml/Placemark/placemark.kml
# to rMaps
sampleKml <- readLines('http://kml-samples.googlecode.com/svn/trunk/kml/Placemark/placemark.kml')
write(sampleKml, file.path(leafletLib, 'placemark.kml'))
# finally try the map
map1
# remove the temp file
file.remove(file.path(leafletLib, 'placemark.kml'))
UPDATE:
There is an addAssets method in rCharts which allows you to add .js files. This allows us to simpilfy things and doesnt require us to write a copy of the js file nor edit the config.yml file.
require(rMaps)
map1 = Leaflet$new()
map1$setView(c(45.5236, -122.675), 13)
map1$tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png")
map1$addAssets(css = NULL, jshead = 'http://harrywood.co.uk/maps/examples/leaflet/leaflet-plugins/layer/vector/KML.js')
map1$addKML('leaflet/placemark.kml')
leafletLib <- file.path(find.package("rMaps"), "libraries", "leaflet")
sampleKml <- readLines('http://kml-samples.googlecode.com/svn/trunk/kml/Placemark/placemark.kml')
write(sampleKml, file.path(leafletLib, 'placemark.kml'))
# finally try the map
map1
# remove the temp file
file.remove(file.path(leafletLib, 'placemark.kml'))

convert .shp file to map with jvectormap-1.2.2

I follow this document and this question.
I have downloaded ne_10m_admin_1_states_provinces files but I can not find
country_code_index (for Iran Or other country) in it.
I use this command in ubuntu command line :
ogrinfo ne_10m_admin_1_states_provinces.dbf -al > Out.txt
out.txt's content is :
How to find --country_code_index AND --country_name_index ?
Go through Map-converter-notes which has very good information about all the steps required to generate a new map from public data.
Linux users can install a very handy tool SAGA-GIS to generate required shape file and then use converter.py to generate map to use with jvectormap.com plugin.
country_code_index is the index of attribute which will be used as code name for specific region on map and country_name_index is the attribute which will be shown as label of region on map. Attributes chosen for these should have unique values in map data table.

Resources