When importing data by pasting them from Excel into <textarea>
, or when working with delimited-text formats like CSV or TSV (tab separated values), the simplest approach is to just split it by newline character into array of lines and iterate over them.
Because you never know, what newline format you're dealing with, I'm always starting by removing \r
character, keeping only \n
:
In the example above I also trimmed out all whitespaces from the beginning and end of the string, which may be unneeded empty lines. But if the data starts with an empty column, this would damage it (shifting columns).
But this approach would fail, if any “cell” contains newline character. In such case the cell value is enclosed mostly by double quotes and CSV parsers usually deal with it. But what if you can't or don't want to use such parsers?
The regular expression below is tailored to such case. It will replace newline character by space and multiple spaces by a single space:
Shoutout to regex101, especially for having a Code Generator.
I already wrote about GeoQetriX, but what’s with the three D-s? Well, 3D sounds quite familiar, doesn’t it? :-) When I started to fool around with Microsoft XNA’s successor, MonoGame, I obviously dipped into 3D graphics as well. Great source of knowledge are Remer’s XNA Tutorials.
I’m still quite new to 2D, so a lot about 3D is total gibberish to me so far, but a lot of things already rings a bell – like the only available shape is a rectangle or terrain is created by a mesh (of rectangles). I know what a vector is, so to get the idea of vertices was no big deal.
But the amount of code, required for the simplest tasks to draw, are somehow incomprehensible to me. In 3D there’s a lot of information required, that’s no brainer, but until this I’ve been always able to shorten the code to just a few lines.
Another option would be to use WebGL, instead of XNA. All the major browsers are already supporting it and there are some great frameworks to help with the complexity of 3D.
Of course I know it will never come even close to Google Maps or OpenStreetMap and I don’t even want to. My personal motivation is to be able to use my own maps for general purposes, like place locators.
So, I’m going to include administrative divisions, preferably up to city boroughs. Plus major roads, major railroads, major rivers and major streets. I have to come up with some compression, I’d like to be able to define, how detailed the export (SVG, PNG) should be. So far I can do it with all lines loaded, which is quite resource inefficient.