I want to display a form with an image, the map of Europe.
How can I achieve that the event handler displays the information belonging to the selected country.
I have discarded the usage of complicated polygon and elliptical shapes.
I have found out another way. I download a map with borders of countries. I fill each country with unique different color. If the user clicks onto a point then the event handler reads the color of it. I will include a table in my program in order to select the country having the chosen color and display the information connected to this country.
Expand|Select|Wrap|Line Numbers
SELECT COUNTRIES.INFO1,COUNTRIES.INFO2 FROM COUNTRIES WHERE COUNTRY.COLOR IS [COLOR_OF_PIXEL_X_Y]
How do you like this idea?
I am a beginner in C#. Please help me in event handling and table generation and queries.
I have found a map and I colored it. I collected country codes, names and RGB triplets in an Excel table.
Regards
Frank
Personally I would advocate the usage of polygons only because the algorithm for detecting if a point is inside a polygon is actually not that bad, and because with this way you're limited to a set of colours. Having said that, RGB space has a ton of colours so you're probably ok.
If you're wondering which event to use, you should probably look into the MouseMove event. I believe the event args will give you a position which you can then use to map back to your image. A Bitmap object has a GetPixel method, which will return the Color at that coordinate. If you're drawing with any scaling/filtering, you'll need to take that into account... so maybe get it working with an unscaled bitmap for now.
Thank you for the suggestions, Gary. Where can I find the algorithm for detecting whether a point is inside a polygon?
Now I have a database of European Countries and the corresponding map.
Expand|Select|Wrap|Line Numbers
Code Name Red Green Blue
~~ tenger 221 221 221 <--sea
AD Andorra 255 0 40
AL Albánia 192 128 255
AT Ausztria 0 210 255
BA Bosznia 234 0 234
BE Belgium 99 255 32
...
The polygons determining the borders European countries are very complicated. I started from a gray scale map, and colored the >40 countries. The problem was that some borders were not continuous and the filling spilled over them.
As you can see, I copied the RGB weights from the color editor window of Irfan view. How can I compare RGB triplets with pixel colors? Has the Pixel.Color object built-in Read, Green and Blue properties, or have I myself to count the bytes from the equations
The algorithm for detecting if a point is inside a polygon is a matter of picking a point outside the geometry and creating a line between that point and the click point. A point is inside the polygon if that test line intersects with your polygon an odd number of times. That is, test each line segment of your polygon and every time that test line intersects, increment a counter. If your polygons are complex, you might want to implement some sort of QuadTree or other space partitioning algorithm so you can more quickly get from your click to your polygon without having to test every single one. I have a basic QuadTree algorithm posted in the insights section here: http://bytes.com/topic/c-sharp/insig...implementation
You could contain your polygons by their bounding box and insert them as such into the quad tree. Use your mouse's click location to give you the closet polygons to the click and then you can test those for intersection. You mentioned your polygons are complex, but I doubt you'd be looking at more than 1000 intersection tests if you use the quad tree and today's processors should handle that no problem.
As I mentioned before though, this is only if you want really accurate detection. Your colour method should work, you just might run into a few troubles with border detection (as I noticed you coloured all the borders in yellow), if you need to add more countries, or if you decide you want to change the colours (though you can use a hit detection map and a draw map).
So with regards to your second question of how to compare the colours, you don't really need to get that complicated. As I mentioned, the Bitmap.GetPixel(x, y) method will return a Color object. You can use this to directly compare against the colours you have.
Here's an example assuming you had a Point called clickLocation, a Bitmap mapImage, and a list of Country obects that have a MapColor property (that you'd have loaded from the database or file)...
Expand|Select|Wrap|Line Numbers
List<Country> countries = /* list of countries */
Bitmap mapImage = /* map image bitmap */;
Point clickLocation = /* mouse click location */;
Color pointColour = mapImage.GetPixel(clickLocation.X, clickLocation.Y);
Gary,
I have returned from a week of vacations. This time I was not dealing with neither e-mails nor C#. I see some problem with my colored countries:
- there are country codes and city names written in grey within the countries,
- there are some white pixels especially at the borders of countries.
And as I mentioned, there are two ways you can deal with those problems...
1) Use bounding polygons
2) Use a hit map image with the colours to detect where the cursor is but draw the map to the screen. You will have duplicate image data here but it's a simpler implementation than 1.
Dear Gary,
Your suggestion that I should maintain two maps is very good.
First map is for the user, with country names and cities; second map for internal usage without them and probably without boundaries themselves.
As usual, an answer leads to a new question.
How can I make the second invisible map from the first visible map?
Recommend me a graphical program, and a menu point on it, to effectively recolor the letters and bytes occasionally remained white to the unique color of the embedding country.
You don't really need to display both maps... just do all your checks against one but actually draw the other.
I'm afraid I don't know a good program to do that specifically, but were I to do it I would probably just do it manually with mspaint or Paint.NET. The latter is a free tool you can get that has a good set of features... their website is here: http://www.paint.net/
Hi,
I am in the stage that the coordinates and the color weights are displayed below in the text boxes under the map.
Next TODO:
I have to select the record in the country grid based on the color codes.
Problem: Why is the record selector on the top of the form instead of its natural place under the data grid?
Further TODO:
Display subset another data set: Travel goals within the selected country.
Captured part of my form: http://http://franknagy.atw.hu/temp/travel.png
Regards
Frank
I'm not entirely sure what your question is... if it's the one about the record selector not being where you expect, I can't really say. It's your code, you may need to do some debugging if it's not behaving how you expect it to.
I am working with an HTML-based form that uses a select element that
requires about 200 options. Is there a way that I can load, or select
one of these options from a file, rather than hardcode...
I'm building a search function for one of my applications. The user has the
option to enter a number criteria of criteria, but none are compulsary. I
need to be able to build up a query string that...
Hi,
Has anyone seen where using SELECT * truncates characters ?
mysql> SELECT * FROM countries;
+-------------+-----------+
| country | capital |
+-------------+-----------+...
Why does 'SELECT * FROM countries' truncate characters and SELECT country
FROM countries does not ?
mysql> SELECT * FROM countries;
+-------------+-----------+
| country | capital |...
Greets to ciwah!
I'm doing a little webproject for a local session event.
Tryin' to meet latest standards i failed to do this:
--snip--
<select name="fromcountry" accesskey="l" title="+">...
Trying to insert into a history table. Some columns will come from
parameters sent to the store procedure. Other columns will be filled
with a separate select statement. I've tried storing the...
Hello All,
I am new to ms-access, i have a table with values as mentioned below. Each of these table are given with a list of Look up values, in order to narrow down the list of values under...
i have two seelct boxes in one row as below
</form>
<table>
<tr><td>
<select name="countrycode" id="countrycode" onchange="showcountrycode
(this.value);">
<option selected>select...
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...