Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a thematic map/coloring certain areas of a map in VB6 1

Status
Not open for further replies.

JCruz063

Programmer
Feb 21, 2003
716
0
0
US
Hello all,

I'm using VB6 and I have a question.

SHORT VERSION:
I need to create a thematic US map, i.e. I need to display a map of a given US state, with each region (county) in the map displayed in a different color, based on values coming from a database.

Thus, in a map that looks like this: each region (county) will be displayed in a different color depending on the database values.

How can I do that?

LONG VERSION
I have jpg images of all US states and each jpg is already divided into regions as the map shown in the link above. In a database, I have the longitude/latitude values of all regions in any given state.

What I think I should do is the following:

1. Load the jpg of a given state into a picture box
2. Locate a region in the picture box
3. Color the region based on some business logic and values coming from a database.

Steps 1 and 3 are simple. I already have the jpg of each state and each jpg already shows the regions. Also, a programmer who worked on this problem before me wrote code which identifies a given region on the picture box using longitude/latitude values for that region, and he writes texts on top of that region - works like a charm.

Step 2 is the problem, however. How on earth can I identify the entire, odd-shaped region of a given county? Can I do this with latitude/longitude alone or do I need some other data which describes the exact area of each region?

Can someone shed some light?

Thanks

_________________________________
I think, therefore I am. [Rene Descartes]
 
Also, if I should be approaching this in a different way, by all means please let me know.

_________________________________
I think, therefore I am. [Rene Descartes]
 
Ideally speaking, you should have a database containing list of points defining each region (county) in the form of a polygon. Using those set of points for each region, you can draw a region using Paths.

Paths will allow you do outline and/or fill any irregular shapes like counties in your case. This will also allow you to scale up or down your pictures creating the effect of zooming in or out of the map. But all of this will require all regions to be defined as polygons, whose vertices are known. I am afraid, this information will not be available in your case.

An easier solution is to use the map image for each state and use ExtFloodFill function to fill each region (county) with the color of your choice. ExtFloodFill function works like the bucket fill tool in Paint.

Assuming the longiture/lattitude values coming from the database are translated into a point coordinate in the center of the region, the ExtFloodFill function will use that point to start filling and continue until the boundary of the region is encountered.

Note that the ExtFloodFill function works by comparing the pixel color values exactly. Any slight change in color values will cause erratic results. Jpeg compression, being lossy in nature, causes the pixel colors to vary slightly from their original value. This will cause ExtFloodFill function to fail and produce undesirable results. To understand this point, open the same picture you linked in your post in MS Paint, and try filling a county with a color. It will never work correctly. The county will only be partially filled.

To avoid this problem, you will need to convert all your pictures to monochorme bitmaps. This will ensure that all your maps have only two colors without any variation, making possible for the ExtFloodFill function to work correctly.
 
This is excellent, thank you!!! I'll give ExtFloodFill a go and report back.

The one issue I can foresee, however, is that in some of the maps I have, some regions are on the edges and are open-ended. I will have to get maps where all regions are closed or find a way to close them myself.

In any case, thanks again. I'll let you know how it goes.

_________________________________
I think, therefore I am. [Rene Descartes]
 
Hey man, ExtFloodFill works like a charm! :)

As you mentioned, I did have the issue where the entire area inside the regions wasn't being filled due to minor gray dots around the darker dividing lines. I simply took each image and applied 100% contrast using Paint.NET and voila - now I have 100% black/white images and ExtFloodFill couldn't work better.

Thanks a million. If I could give you 5 stars I would, but alas...!

_________________________________
I think, therefore I am. [Rene Descartes]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top