Skip to main content

Posts

Use NetworkX for GEOframe topology

A basin network can be seen as a graph, specifically as a directed acyclic tree . In GEOframe , the topology of the basins, which describes the direction of the flow and the interconnections of the basins, is usually saved in a text file with two columns: the first column represents the origin basin , and the second column represents the target basin . The 0 is used to mark the outlet of the network. For example: 8 7 7 4 6 5 5 4 4 3 3 2 2 1 1 0 The 0 mark the outlet. In my work, I've encountered the need to manipulate basin networks so verifying the topological correctness of these new graphs is crucial. To accomplish this task, I chose the NetworkX Python library. This library facilitates a variety of tasks—such as cutting the network, iterating through the network, and comparing two or more networks within the same watershed—thanks to its class structure, specifically the Graph class. As a result, I've developed some functions for basic operations on the network and shar
Recent posts

Julia programming: My Journey Begins at EGU

The Beginning It's been a long time since I first heard about Julia . Despite my interest, I never got around to actually studying it. That changed recently when I attended a short course on Julia at the last EGU General Assembly . Inspired by what I learned, I returned home determined to dive into programming with Julia. First Steps I started with a basic book on Julia, aiming to build a solid foundation. The simplicity and power of the language fascinated me, and soon, I felt ready to take a more hands-on approach. My Project: A Julia Package As I gained confidence, I began writing my own package. This project is still a work in progress on github. The package includes: Reading Time Series: It can read a time series from a CSV file, handling special formatting and metadata. Goodness of Fit Functions. Graph Operations on river networks.(in progres) Geometry/Geography Operations. Focus on Geography In this blog post, I want to delve into the last point —

Read magnetic strip card data in Android

Recently I have developed an app with the purpose to read data from an USB card reader. The data to be read are stored on a plastic card organized in this way:  a start tag; a fixed field (length of 17 char); two other fields separated by a white space with no size declarad but always present; an end tag.  The external USB card reader is something similar to an external keyboard so it's possible to override the appropriate method in the  Activity to handle every single character read from the reader. The Activity manages the card data character by character so  firstly I had to create a UsbDecoder class to manage the data flow and to build my output values. Lastly. I had to implemented the onKeyDown to intercept the data from the reader: @Override public boolean onKeyDown(int keyCode, KeyEvent event) { char pressedKey; if (event.getKeyCode() == KeyEvent.KEYCODE_SPACE || event.getKeyCode() == KeyEvent.KEYCODE_TAB) { pressedKey = Character

RESTFull GEOJson with Swagger and Slim

I often find myself having to write RESTFull api for small project.  So I have search and tried several tools. I finally choose to use  Swagger  to write the documentation and  Slim micro framework  to implements it. The first step is writing the yalm file in the Swagger editor (there is a nice tutorial at  Api Handyman  blog). With the yalm specification file it's simple to build an html documentation. Swagger have two pre build schema in html (html and html). You can export it, from Swagger Editor with Generate Client button (where you can export other languages client code).  To create the Slim skeleton, simply click on the Generate server button and choose Slim. Now you have two zip file that contains documentation and the skeleton code. Usually my project folder is composed by three subfolders: app (with the api code), api_doc (with the documentation generated by Swagger) and then an db_doc (the database documentation with diagram). To provide a geographic information

A leaflet template for ionic

Leaflet is a very useful javascript library to insert map into an app. It has lots of extensions, which simplify it's use. I use it mainly in ionic's app, so I have created a repo on GitHub as a start point. It's extends the  side menu template  with leaflet. The key points are: Get a GeoJson  through an api call (markersApi.js) Create a map (with OSM as baselayer). Add the GeoJson to the map (using the  marker-cluster library ). Add a marker on tap. Add the map to the html To add leaflet map in ionic (and angular) there is a directive to simplify it: angular-leaflet-directive  (or you can use ui-leaflet ). In the html you can just put: <leaflet data-tap-disabled="true" defaults="map.defaults" id="map" layers="map.layers" lf-center="map.center"></leaflet> And after you have incluse in the app's model dependencies, the angular-leaflet directive, and have defined an object in the controlle

My notes on JavaScript

I started study JavaScript about one years ago, I studied the basic rule and then, due to my work, I moved quickly to use some framework ( Ionic and Angular ) so I omitted to study it in depth and also  the best practise... Because of this bad start, this December, I re-started to study and I'm writing some notes (mainly on different things than other languages). Variables keyword const, to declare a constant. Number : Number. NEGATIVE_INFINITY < Number.MIN_VALUE < Number.MAX_VALUE < Number.POSITIVE_INFINITY . Math is an "object" with the most common mathematic functions. Some useful method of Number: parseInt(), parseFloat(), isNaN(), isInfinite(). Multiline string , useful to include variable values into the string: var a=2; var b=2; var myString=`this is my value ${a+b} `; The if statement To test if an array is empty, simply use if( myArray.length ) not if( myArray.length>0 ). To test if a string is vo

Notes about SQLite

I'm using SQLite in several project, mainly in mobile app (Android SDK or with Cordova plugin). SQLite is the best solution to store data locally, but when using it?  Maybe it's better to understand when does't use it: IF data are detached from the app OR there are lots of concurrent writers OR Big Data THEN t's better build a server side services (client-server) OTHERWISE  SQLite Main Properties: self-contained serverless zero-configuration transactional: Atomic,Consistent,Isolated, Durable (ACID) SQLite han't all feature that usually a server side db (as MySQL) have: Right and full outer join. ALTER TABLE isn't completely supported. There isn't Date and Time DataType but it's possible to store data as a REAL (Julian day number), INTEGER (Unix time) or TEXT (ISO8601) and extract it by specific function. I prefer store date as text so for example the today's date is strftime("%s",'now') or use in a query as