views:

188

answers:

6
+2  A: 

Your brush pattern colors some pixels black and leaves some pixels alone. Instead of leaving the pixel alone, can you set up your brush pattern to color those pixels white (or whatever your background color is)?

Another possibility is to always draw your county borders twice -- once with a solid white pattern, and again with the brush pattern of your choice.

mobrule
That's a clever solution but it won't work on anti-aliased drawings. You always end up getting pixel-gunk around the edges.
David Rutten
Anti-aliasing is the problem, yeah, because solid white isn't desirable, I need the layers underneath to show through where there are no dashes.
Doug McClean
Although... if I do all the drawing and then all the compositing, instead of compositing as I draw, the solid-white then dashed plan could work really well. Good idea!
Doug McClean
Careful there. It sounds like you're complicating everything just to solve this problem in a particular way. It would be far preferable to somehow find a way to *not* draw those overlapping segments to begin with.
David Rutten
Agreed, David, but I thought it was worth pointing out that this idea could actually work out since I had in haste inaccurately said that it couldn't.
Doug McClean
+2  A: 

The artifact is due the fact that the piece of border is drawn twice. Instead of trying to supress such artifacts, you could try to not draw border sections twice, by keeping a list of segments already drawn in memory, and if you encounter a stretch that's already drawn, you don't draw it again.

cdonner
That works, but splitting it into individual segments means both a very large number of segments and a fairly complicated system for propagating where you are in the dash pattern as you move from one segment to the connecting one (something that is handled by GDI+, including the correct anti-aliasing, if I draw whole paths).
Doug McClean
Ok, if you don't want to lose the position in the pattern, can you switch to a transparent pen over already drawn segments? I don't think that that your point is valid, though, because if you have two lines converging into one, the pattern can only be continuous for one the lines (the one you drew first), not both.
cdonner
I think the confusion here is disagreement over what constitutes a segment. The polylines in reality are a lot more jagged than in the sample image above, and have lots of twists and turns at spots other than intersections with other counties. If we split it into each little straight segment, that introduces a ton of places where the pattern will get lost. You're correct that at a junction it can only be continuous for one line or the other, that's not that big a deal though.
Doug McClean
I am not saying that you need to split it into each segment, just that you need to eliminate segments that overlay others. Assuming that the neighboring polylines share points, you can determine all line segments in a polyline and store them in a list. You need the segments only for comparison, not for the drawing operation. Then you prepare the next polyline and compare each segment in the polyline with what you've already drawn. If there is a match, you remove the affected segments from the polyline. You will run into situations where the remaining polyline is not contiguous.
cdonner
Only then do you need to break it up into multiple polylines.
cdonner
Ahh, that's a good idea. I like it.
Doug McClean
+2  A: 

I suppose they break their border lines into segments, then remove the overlaps.

This is mostly a geometric problem, not a drawing problem.

David Rutten
True, it is mostly a geometric problem. I considered trying to preprocess the boundaries in the database to remove this kind of duplication, but that ends up duplicating the data (or with a complicated bookkeeping scheme) because I need the polygons themselves to do fills, intersection tests, and membership tests.
Doug McClean
I haven't tried this, but if I were to try it I'd approach it like this:1) Create a class that represents a single line segment, i.e. 4 numbers that describe the coordinates of the start and end points.2) Create a method that compares two of these segments (add some tolerance to the comparison). Make sure they evaluate as identical even when they travel in opposite directions.3) When drawing, build a dictionary of all segments and test every new segment against the dictionary.If this works you may solve this without any geometry intersection operations.
David Rutten
Right, but you can't just build the dictionary and then iterate over it drawing segments, because (at least for my data) segments tend to be small relative to the dash pattern (on order of half a repeat distance or less). You need to then put them back into some kind of order so that the dash pattern will match up at segment boundaries.
Doug McClean
Ok, then you're screwed. You're going to have to somehow find overlaps between two given polygons and cut out the shared bit... I don't envy you.
David Rutten
Yup, that about sums it up. :)
Doug McClean
Last ditch suggestion, you *could* explode your polygons, remove all duplicate segments, then join the results together again. At least this will fix your dash continuity.
David Rutten
That's a good idea, and if I expanded the segments class in your note above to include pointers to the previous/next segments (there might be more than two, if one or more end of the segment is a junction) it might not even be too difficult. I am going to look into that and possibly write it up as another answer. Thanks David.
Doug McClean
A: 

This is an interesting question that I never really thought about. I think the only real solution is to render the entire complex figure as a series of lines or paths that do not overlap anywhere. I'm not surprised that GDI+ doesn't handle this situation in any automatic way.

MusiGenesis
Totally. I don't blame GDI+ at all, I'm just trying to get a feel for how others have handled this situation.
Doug McClean
It *is* an interesting problem, although I would probably just use a solid light grey (gray?) line for this. I admit that's totally cheating. :)
MusiGenesis
+2  A: 
MusiGenesis
I like your style, and I upvoted this, but the style is pretty much prescribed by a standards document and longstanding practice so I think I have to go with the more complicated duplicate-segment-identification approach. You could do this with textured brushes pretty easily, I would think.
Doug McClean
@Doug: yeah, textured brushes do this automatically (I just tried it). I thought maybe the textured brush would produce off-by-one-pixel errors based on where the lines and shapes were drawn, but it draws everything from one tiled sheet of the texture bitmap *a la* zip-a-tone.
MusiGenesis
@Doug: your task sounds potentially very painful. What do you do when two lines overlap only partially?
MusiGenesis
I think we are going to do the detection offline when we do all the other topology checks on the geo data, so if they overlap only partially we will complain to the cartographers and make them stitch it up one way or the other. Sadly a lot of our input data has A's boundary on one side of a river and B's a few tens of meters away on the other side, rather than down the center, so there will be a reasonable amount of work involved in cleanup. That's ok, though, we've had to do similar stuff before to fix other topology problems.
Doug McClean
A: 

you are a very mad person you have write a 3 fclass thing

manan

related questions