Rotating a Point Around a Base Point

A while back, I was working on a project that required us to rotate a polygon around a base point and do a spatial query to analyze some underlying demographic data. I was working in ArcObjects and could find no intrinsic way to do what I needed to do so I wrote the following routine. As you can imagine, I had to break the polygon up into individual points and rotate each one. Despite the fact that I was using ArcObjects point objects and all of the attendant COM interop calls, it worked pretty well (a polygon consisting of ~5000 point was rotated in less than a second on a less-than-robust workstation).

The math is pretty simple: Assuming that the base point and target point form the two ends of the hypotenuse of a right triangle with one leg of the triangle being a segment of the X axis, you simply:

  1. Calculate the length of the hypotenuse
  2. Calculate the current angle of the hypotenuse
  3. Add the rotation angle to the current angle
  4. Calculate the coordinates of the new end point of the hypotenuse

The code below shows how to do it but there are a couple of notes about it:

  • The coordinates must be in decimal degrees so you’ll need to unproject any projected coordinates and then re-project the result. This may introduce some distortion. I didn’t notice any in my application but I’d suggest some more rigorous testing if you’ve got tight precision requirements.
  • Rotation follows engineering standards (zero East, counter-clockwise)
  • This code is only mildly based on ArcObjects. It uses the AO IPoint interface and Point but that’s it. It is trival to implement it with another point object (such as SharpMap) or just use numeric values.
  • The base point is shifted to 0,0 and the same offset is applied to all other points in order to keep the math straightforward.
  • It’s in C#

So there it is. It’s fairly simple but it’s been useful for me on a couple of occasions since I wrote it.
[sourcecode language=”csharp”]
private IPoint rotatePoint(IPoint basePoint, IPoint sourcePoint, double rotationAngle)
{
double r;
double theta;
double offsetX;
double offsetY;
double offsetTheta;
double rotateX;
double rotateY;
double rotationRadians;
IPoint retPoint;
try
{
//shift x and y relative to 0,0 origin
offsetX = (sourcePoint.X + (basePoint.X * -1));
offsetY = (sourcePoint.Y + (basePoint.Y * -1));
//convert to radians. take absolute value (necessary for x coord only).
offsetX = Math.Abs(offsetX * (Math.PI / 180));
offsetY = offsetY * (Math.PI / 180);
rotationRadians = rotationAngle * (Math.PI / 180);
//get distance from origin to source point
r = Math.Sqrt(Math.Pow(offsetX, 2) + Math.Pow(offsetY, 2));
//get current angle of orientation
theta = Math.Atan(offsetY / offsetX);
// add rotation value to theta to get new angle of orientation
offsetTheta = theta + rotationRadians;
//calculate new x coord
rotateX = r * Math.Cos(offsetTheta);
//calculate new y coord
rotateY = r * Math.Sin(offsetTheta);
//convert new x and y back to decimal degrees
rotateX = rotateX * (180 / Math.PI);
rotateY = rotateY * (180 / Math.PI);
//shift new x and y relative to base point
rotateX = (rotateX + basePoint.X);
rotateY = (rotateY + basePoint.Y);
//return new point
retPoint = new PointClass();
retPoint.X = rotateX;
retPoint.Y = rotateY;
return retPoint;
}
catch
{
return sourcePoint;
}
}[/sourcecode]

How Do You Disable This Dialog in ArcMap?

**UPDATE**Check the comments for the resolution to this. 9.2 offers a registry setting and, since I’m upgrading, I’ll make use of that. I got pretty far on my API hack though.

My question is twofold: First: Can you stop this dialog from appearing in ArcMap 9.1? Second: If not, does 9.2 give you the option to turn this thing off?

ArcMap Drawing Errors Dialog

I have posted a similar query on the ESRI forums but I thought the blogosphere may be able to weigh in on this. This dialog was introduced at 9.1 as a “feature” but it’s not the most developer-friendly thing in the world. A little background:

I have an application running as a Windows service that is receiving data and stuffing it into ArcSDE. I have another app that’s an ArcMap extension. It refreshed the map on a specified interval and shows the new data as it comes in. There is no syncronization between the two. As you would expect, there are occaionally collisions. The ArcSDE layer may be in load-only mode or something similar. I have a lot of exception-handling in place to trap all of those kinds of things.

This dialog defies all of that. Despite my exception handling, it still pops up and it completely freaks out my users. I would like to turn it off. (I would really like to kill it.) I can’t find a registry setting or any other such option that allows me to do that so I’m stumped. Any help would be appreciated and I promise to sing your praises on this blog if you have the solution.

For background: we are using 9.1 (for a number of reasons). We are starting the upgrade planning to go to 9.2. If 9.2 fixes this, then I’ll stop worrying about it. Any useful info would be very helpful. My next step is some slimy Windows API hack to suppress the damned thing.

Two Roads Diverged in a Yellow Wood…

With apologies to the great Robert Frost.

I’ll admit that over the last few months I’ve become something of an open-source convert. I’ve been in the consulting business for about 15 years now and I’ve made through the “holy wars” relatively unscathed (Microsoft/Linux, IE/Netscape/Firefox, Oracle/Everyone else, ad nauseum). I’ve said it before that it’s not religion, it’s technology. I’ve gotten to this particular point in my career with two basic philosophies intact: 1) Nothing big works and 2) I can do whatever you need to do on whatever platform you want with whatever tools you give me; it’s just a matter of “how.”

Most of my GIS consulting work over the years has been with ESRI technologies and it’s served me and my customers well. In general, it works and, more importantly, I know how it works. But over the last couple of years, there has been a disturbing trend with the technology: it’s gotten more complex (nothing big works) and more expensive. When my Federal customers start to balk, I know there’s a problem. In addition, there’s ESRI itself. It is still a privately held company with an owner that’s not getting any younger. Lacking any evidence of a transition plan that maps out how the next 10 to 15 years will go, I’ve begun doing the only responsible thing for my company and my customers: hedging my bets.

Given that most of ESRI’s serious commercial competition imploded years ago (don’t try to debate that with your single-digit-market-share tool of choice), I began paying more attention to open-source products. The approach I’ve taken is to try to piece together an open-source architecture that I would feel as comfortable recommending to a customer as the ESRI architecture. My focus has begun to gel around a core few: GeoServer, SharpMap, PostgreSQL/PostGIS and QGIS. Also key for me is that any client technology must be able to take advantage of Oracle Spatial. It’s not open-source, but it’s everywhere.

Being a programmer from the ArcObjects/ArcSDE mold, the ones I’ve been having the most fun with are SharpMap and PostGIS. As I’ve posted before, I even joined the zigGIS project to enable connectivity between PostGIS and ArcGIS. That’s been the most fun I’ve had in a long time. Probably the weakest link so far is the lack of a really good desktop tool that I could put in front of one of my analysts and say “make a map that looks as good as the ones you make in ArcMap.” QGIS is on the right track but still pretty far from the station. My analysts, thus far, won’t give it a second look.

So how has all of this made me a convert? It’s come down to the simple convenience of open-source. I’m still doing a lot of experimenting. Some of my existing customers are really interested in implementing open-source but can’t quite make the switch yet. So I was playing around with a very simple tool I was trying to build using SharpMap and I just couldn’t get it to work. I figured I had to be doing something wrong so I opened up SharpMap’s source code and examined the class I was using, realized my mistake, and moved on. The power and simplicity of that act, compared to the years of hacking against ArcObjects bugs and documentation, was breathtaking. It’s raised the bar significantly in terms of my expectations of software.

Now to step back from the edge a little: It’s not religion. Most of my customers use, and are committed to, ESRI technology. I’ve had a good working relationship with the company and the people in it. Also, quite frankly, many open-source tools are very immature and unstable. But, as ESRI shifts their focus more to the enterprise market, there will be an increasing number of small of mid-sized users getting into the geospatial game for the first time who will feel priced out. For my part, it would be irresponsible not to be prepared to address their needs with an alternate set of technologies. It will be interesting to see which becomes the road less traveled.

Free and Closed. Why?

I was IMing with Paolo today and we were discussing his employer’s decision to migrate to open-source. The conversation took a few turns and we touched upon the concept of free closed-source software vice free open-source software. His employer had rejected a free CMS that was not open-source.

This got me into a philosophical frame of mind. I began wondering if, in this day and age, there is any reason to consciously choose to release a software product as a free, but closed-source product? I raised this question a while back with regard to ArcGIS Explorer but now I’m expanding the question. I would love to hear comments on this but I’d like to establish a few parameters:

  1. I’m not interested in delving into the open-source vs. commercial software debate.
  2. I’m not trying to criticize anyone who chooses to keep their source code closed. I’m genuinely curious about the decision process.
  3. I’m not referring to things like “nagware”, demo software with restricted functionality or free products that are really teasers for commercial products (which is what I consider Google Earth to be).
  4. Please keep it civil. We’re all grown-ups and/or professionals.

I look forward to hearing your thoughts.