There’s a part of Maryland where traveling in almost any cardinal direction — south, east, or west — will put you in West Virginia. It’s called Western Maryland, and it comprises Garrett, Allegany, and Washington Counties. If you combine those three counties with neighboring Frederick and Carroll Counties — five counties that border Pennsylvania and are west of Baltimore — you could get a congressional district.

It would be a coherent district, mostly rural, hilly, and fairly geographically compact. Basically an Appalachia district, It would also set up similarly coherent lines for the remaining seven districts of Maryland. So, why is there no Western Maryland congressional district? Because such a district would probably elect a Republican. Democrats, who controlled the legislature and the governor’s mansion in 2011, couldn’t have that.

So, Democrats in Annapolis drew a 6th District that roped in the Appalachia part of Maryland with the Bethesda Country Club, hundreds of miles away, in the wealthiest parts of the country. The Democrats also took part of Frederick and Carroll counties and drew them in with Chevy Chase, the wealthiest municipality in the region, in a hideous-looking 8th District.

After that, the districts get uglier. The southeastern appendage of the 3rd District is contiguous only if you have a sailboat. A completely different region of the 3rd tangles with 2nd in an embrace so intimate that it would take a pulp romance novelist to adequately describe it.

Maryland’s 7th and 4th districts — each with arms, and jowls, and connective corridors so narrow you need advanced observation equipment to spot them — would be the ugliest districts in almost any other state. The net result: In a state where Democrats get about 5 in every 8 votes for Congress, they control 7 of 8 congressional districts.

The absurdity of this map, and the blatant partisan purposes behind the lines of the map, are why a federal court has ruled the map unconstitutional. The legal questions here are novel and complicated, but from a good governance perspective, this sort of gerrymandering needs to end.

Republicans do their own gerrymandering, of course, with Pennsylvania and North Carolina being the worst examples. Democratic judges in Pennsylvania responded by drawing their own map, swinging an immodest Republican gerrymander to a modest Democratic gerrymander. That’s no good, either. Judges shouldn’t get to determine the shape of the legislature — that’s backwards.

The predicament, then, is this: It’s properly up to legislatures to set congressional districts, but letting partisans with a direct interest in the result do the drawing results in abuse. We’ve seen state legislative leaders draw congressional districts just for them to run in or have them tailor-made for their children.

What to do about it? Look at Iowa. There, a nonpartisan panel draws a map — for the legislature’s ratification — bound by rules and guidelines. In Iowa, a congressional district needs to be compiled by piecing together state Senate districts, which in turn need to be compiled by pairing state House districts.

They operate under principles that constrain creativity of the nonpartisan drawers. Counties are to be kept intact whenever possible.

We would add other principles. Geographic compactness is a virtue. Keeping together communities of interest is also a venerable idea here. For instance, keep the rural, hilly parts of Maryland in one district; the suburban, upper-middle-class parts of Montgomery County in another; and the urban core of Baltimore in another. Draw an Eastern Shore district, two more D.C.-suburbs district, a Southern Maryland district, and a final district tying together Annapolis and the suburbs east and south of Baltimore.

Such lines would allow congressmen to be more representative of their districts by making their districts as coherent as possible. In some states, switching to a reasonable map would help the out-of-power party. In others, it would make incumbents less safe. That's good. We like competition.

Whether the federal or state courts rightly have a hand in redistricting is an open question. State legislatures, though, can do their part to dampen the partisan warfare of the day through an old conservative idea: Establishing rules and respecting communities.