1

Let me preface this by stating that I know I'm in the GIS neighborhood and I'm asking a code heavy question, but my hiccup here isn't the programming - it's the GIS and associated math.

I am writing some C# code that will crop an oblique photograph to a 1500 pixel square surrounding a geographic point and I am having trouble with finding the right formula to translate geographic coordinates to pixel coordinates with the following known variables:

  1. Feature geographic shape and centroid (State Plane)
  2. Photo geographic centroid (State Plane)
  3. Photo geographic footprint (Polygon shapefile [State Plane])
  4. Aircraft position at time of photo (State Plane)
  5. Pixel coordinates of photo centroid
  6. Aircraft altitude in feet
  7. Focal length of lens (50mm)

The oblique photo metadata is stored in shapefiles and served to my application via ArcGIS server

Here is the code I have so far

        double originX = xg_0;  //Geographic centroid of photo (State Plane) (X)
        double originY = yg_0;  //Geographic centroid of photo (State Plane) (Y)
        double x0 = -1 * (originX);
        double y0 = -1 * (originY);

        aircraftX = aircraftX + x0;  //Aircraft position in state plane adjusted to (0,0) geographic origin at centroid
        aircraftY = aircraftY + y0;  //Aircraft position in state plane adjusted to (0,0) geographic origin at centroid

        double pixelCenterX = xp_0;
        double pixelCenterY = Math.Abs(yp_0);

        double featureX = xg_1 + x0;  //Feature point (or centroid) in state plane adjusted to (0,0) geographic origin at centroid
        double featureY = yg_1 + y0;  //Feature point (or centroid) in state plane adjusted to (0,0) geographic origin at centroid

        double pixelX = 0.0;
        double pixelY = 0.0;

        double groundDistanceToCenter = Math.Sqrt((Math.Pow((featureX - 0), 2)) + (Math.Pow((featureY - 0), 2)));  //Distance in feet from photo centroid to feature
        double groundDistanceToAircraft = Math.Sqrt((Math.Pow((featureX - aircraftX), 2)) + (Math.Pow((featureY - aircraftY), 2))); //Distance in feet from aircraft to feature
        double height = 5000.0; //aircraft altitud in feet
        double imageAngle = Math.Atan(height / groundDistanceToAircraft) * 180 / Math.PI; //viewing angle from feature to aircraft


        double u = featureX - (featureY * (1 / Math.Tan(imageAngle)));
        double v = featureY * (1 / (Math.Sin(imageAngle)));
        double imageStatePlaneX = u + (v * Math.Cos(imageAngle));
        double imageStatePlaneY = v * Math.Sin(imageAngle);
        pixelCoordinates = new Point((int)(pixelCenterX - imageStatePlaneX), (int)(yp_0 - imageStatePlaneY) + 4912);  //4912 is pixel height of image

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.