|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 |
| - "execution_count": 33, |
| 5 | + "execution_count": 2, |
6 | 6 | "metadata": {},
|
7 | 7 | "outputs": [
|
8 | 8 | {
|
|
57 | 57 | },
|
58 | 58 | {
|
59 | 59 | "cell_type": "code",
|
60 |
| - "execution_count": 12, |
| 60 | + "execution_count": 3, |
61 | 61 | "metadata": {},
|
62 | 62 | "outputs": [
|
63 | 63 | {
|
|
66 | 66 | "('32bit', 'WindowsPE')"
|
67 | 67 | ]
|
68 | 68 | },
|
69 |
| - "execution_count": 12, |
| 69 | + "execution_count": 3, |
70 | 70 | "metadata": {},
|
71 | 71 | "output_type": "execute_result"
|
72 | 72 | }
|
|
78 | 78 | },
|
79 | 79 | {
|
80 | 80 | "cell_type": "code",
|
81 |
| - "execution_count": 34, |
| 81 | + "execution_count": 8, |
82 | 82 | "metadata": {},
|
83 | 83 | "outputs": [
|
84 | 84 | {
|
85 |
| - "name": "stdout", |
86 |
| - "output_type": "stream", |
87 |
| - "text": [ |
88 |
| - "Coordinates transformed from Ålesund 110 to EUREF89-32N\n", |
89 |
| - "World file created: ../datasets/aalesund/1504200/200.jgw\n", |
90 |
| - "Image georeferencing parameters have been written.\n" |
| 85 | + "ename": "RuntimeError", |
| 86 | + "evalue": "Failed to init transformation", |
| 87 | + "output_type": "error", |
| 88 | + "traceback": [ |
| 89 | + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", |
| 90 | + "\u001b[1;31mRuntimeError\u001b[0m Traceback (most recent call last)", |
| 91 | + "Cell \u001b[1;32mIn[8], line 50\u001b[0m\n\u001b[0;32m 48\u001b[0m _InitSkTrans(href, ctypes\u001b[38;5;241m.\u001b[39mbyref(sLen), ctypes\u001b[38;5;241m.\u001b[39mbyref(sErr))\n\u001b[0;32m 49\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m sErr\u001b[38;5;241m.\u001b[39mvalue \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m---> 50\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFailed to init transformation\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 52\u001b[0m \u001b[38;5;66;03m# Ålesund-lokal -> EUREF89-32N\u001b[39;00m\n\u001b[0;32m 53\u001b[0m \u001b[38;5;66;03m# According to given info:\u001b[39;00m\n\u001b[0;32m 54\u001b[0m \u001b[38;5;66;03m# slSys1=4; slZone1=1 for Ålesund-lokal\u001b[39;00m\n\u001b[0;32m 55\u001b[0m \u001b[38;5;66;03m# slSys2=7; slZone2=32 for EUREF89-32N\u001b[39;00m\n\u001b[0;32m 56\u001b[0m slSys1 \u001b[38;5;241m=\u001b[39m ctypes\u001b[38;5;241m.\u001b[39mc_short(\u001b[38;5;241m4\u001b[39m)\n", |
| 92 | + "\u001b[1;31mRuntimeError\u001b[0m: Failed to init transformation" |
91 | 93 | ]
|
92 | 94 | }
|
93 | 95 | ],
|
|
113 | 115 | "# If koordsys is 110 (Ålesund), transform to EUREF89-32N using the DLL\n",
|
114 | 116 | "if koordsys == 110:\n",
|
115 | 117 | " # Load and initialize the transformation\n",
|
116 |
| - " dll_path = r\"C:\\Users\\siver\\ScanAI\\sos_coordinate_extracting\\skt2_1507-1504_1.dll\"\n", |
117 |
| - " href_file = r\"C:\\Users\\siver\\ScanAI\\sos_coordinate_extracting\\HREF2018B_NN2000_EUREF89.bin\"\n", |
| 118 | + " dll_path = r\"C:\\Users\\SivertEspelandHusebø\\ScanAI\\sos_coordinate_extracting\\skt2_1507-1504_1.dll\"\n", |
| 119 | + " href_file = r\"C:\\Users\\SivertEspelandHusebø\\ScanAI\\sos_coordinate_extracting\\HREF2018B_NN2000_EUREF89.bin\"\n", |
118 | 120 | " if not os.path.exists(dll_path):\n",
|
119 | 121 | " raise FileNotFoundError(\"DLL file not found.\")\n",
|
120 | 122 | " if not os.path.exists(href_file):\n",
|
|
181 | 183 | "else:\n",
|
182 | 184 | " print(\"Coordinate system is not Ålesund 110. Using coordinates as is.\")\n",
|
183 | 185 | "\n",
|
184 |
| - "image_path = \"../datasets/aalesund/1504209/209.jpg\"\n", |
| 186 | + "image_path = \"../datasets/aalesund/1504200/200.jpg\"\n", |
185 | 187 | "img = Image.open(image_path)\n",
|
186 | 188 | "width, height = img.size\n",
|
187 | 189 | "\n",
|
|
206 | 208 | },
|
207 | 209 | {
|
208 | 210 | "cell_type": "code",
|
209 |
| - "execution_count": 1, |
| 211 | + "execution_count": 19, |
210 | 212 | "metadata": {},
|
211 | 213 | "outputs": [
|
212 | 214 | {
|
213 | 215 | "name": "stdout",
|
214 | 216 | "output_type": "stream",
|
215 | 217 | "text": [
|
216 | 218 | "KOORDSYS: 110\n",
|
217 |
| - "Extracted Coordinates: [(497980.0, 9179.0), (498909.0, 11036.0)]\n", |
| 219 | + "Extracted Coordinates: [(497197.0, 16073.0), (498310.0, 16976.0)]\n", |
218 | 220 | "Sorted Coordinates:\n",
|
219 |
| - "X_min: 497980.0, X_max: 498909.0\n", |
220 |
| - "Y_min: 9179.0, Y_max: 11036.0\n" |
221 |
| - ] |
222 |
| - }, |
223 |
| - { |
224 |
| - "ename": "OSError", |
225 |
| - "evalue": "[WinError 193] %1 is not a valid Win32 application", |
226 |
| - "output_type": "error", |
227 |
| - "traceback": [ |
228 |
| - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", |
229 |
| - "\u001b[1;31mOSError\u001b[0m Traceback (most recent call last)", |
230 |
| - "Cell \u001b[1;32mIn[1], line 232\u001b[0m\n\u001b[0;32m 229\u001b[0m create_world_file(image_path, easting_min, northing_min, easting_max, northing_max)\n\u001b[0;32m 231\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;18m__name__\u001b[39m \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m__main__\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m--> 232\u001b[0m \u001b[43mmain\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", |
231 |
| - "Cell \u001b[1;32mIn[1], line 196\u001b[0m, in \u001b[0;36mmain\u001b[1;34m()\u001b[0m\n\u001b[0;32m 194\u001b[0m \u001b[38;5;66;03m# Initialize transformation if KOORDSYS is 110 (Ålesund)\u001b[39;00m\n\u001b[0;32m 195\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m koordsys \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m110\u001b[39m:\n\u001b[1;32m--> 196\u001b[0m trans_dll, _InitSkTrans, _GeoTrans \u001b[38;5;241m=\u001b[39m \u001b[43minitialize_transformation\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdll_path\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mhref_file\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 197\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mTransformation DLL initialized successfully.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 199\u001b[0m \u001b[38;5;66;03m# Define system and zone codes\u001b[39;00m\n", |
232 |
| - "Cell \u001b[1;32mIn[1], line 63\u001b[0m, in \u001b[0;36minitialize_transformation\u001b[1;34m(dll_path, href_file)\u001b[0m\n\u001b[0;32m 60\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mexists(href_file):\n\u001b[0;32m 61\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mFileNotFoundError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mHREF file not found.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m---> 63\u001b[0m trans_dll \u001b[38;5;241m=\u001b[39m \u001b[43mctypes\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mCDLL\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdll_path\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 65\u001b[0m \u001b[38;5;66;03m# Define argument and return types for _InitSkTrans\u001b[39;00m\n\u001b[0;32m 66\u001b[0m _InitSkTrans \u001b[38;5;241m=\u001b[39m trans_dll\u001b[38;5;241m.\u001b[39m_InitSkTrans\n", |
233 |
| - "File \u001b[1;32mc:\\Python312\\Lib\\ctypes\\__init__.py:379\u001b[0m, in \u001b[0;36mCDLL.__init__\u001b[1;34m(self, name, mode, handle, use_errno, use_last_error, winmode)\u001b[0m\n\u001b[0;32m 376\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_FuncPtr \u001b[38;5;241m=\u001b[39m _FuncPtr\n\u001b[0;32m 378\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m handle \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m--> 379\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_handle \u001b[38;5;241m=\u001b[39m \u001b[43m_dlopen\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 380\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 381\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_handle \u001b[38;5;241m=\u001b[39m handle\n", |
234 |
| - "\u001b[1;31mOSError\u001b[0m: [WinError 193] %1 is not a valid Win32 application" |
| 221 | + "X_min: 497197.0, X_max: 498310.0\n", |
| 222 | + "Y_min: 16073.0, Y_max: 16976.0\n", |
| 223 | + "Initializing transformation...\n", |
| 224 | + "Transformation DLL initialized successfully.\n", |
| 225 | + "Coordinates transformed from Ålesund 110 to EUREF89-32N\n", |
| 226 | + "Transformed Bottom-Left: (Easting: 364010.2971850267, Northing: 6928533.038357328)\n", |
| 227 | + "Transformed Top-Right: (Easting: 364962.85623642476, Northing: 6929603.448842814)\n", |
| 228 | + "Pixel Size X: 0.21083644342586796 meters/pixel\n", |
| 229 | + "Pixel Size Y: -0.19231234018801652 meters/pixel (negative for north-up)\n", |
| 230 | + "Top-Left Pixel Coordinates: (Easting: 364010.2971850267, Northing: 6929603.448842814)\n", |
| 231 | + "World file created: ../datasets/aalesund/1504201/201.jgw\n", |
| 232 | + "Image georeferencing parameters have been written.\n" |
235 | 233 | ]
|
236 | 234 | }
|
237 | 235 | ],
|
|
285 | 283 | "def initialize_transformation(dll_path, href_file):\n",
|
286 | 284 | " \"\"\"\n",
|
287 | 285 | " Initializes the coordinate transformation using the provided DLL and HREF file.\n",
|
288 |
| - "\n", |
289 |
| - " Args:\n", |
290 |
| - " dll_path (str): Path to the transformation DLL.\n", |
291 |
| - " href_file (str): Path to the HREF file.\n", |
292 |
| - "\n", |
293 |
| - " Returns:\n", |
294 |
| - " tuple: (trans_dll, _InitSkTrans, _GeoTrans)\n", |
295 | 286 | " \"\"\"\n",
|
296 | 287 | " if not os.path.exists(dll_path):\n",
|
297 | 288 | " raise FileNotFoundError(\"DLL file not found.\")\n",
|
298 | 289 | " if not os.path.exists(href_file):\n",
|
299 | 290 | " raise FileNotFoundError(\"HREF file not found.\")\n",
|
300 | 291 | " \n",
|
301 |
| - " trans_dll = ctypes.CDLL(dll_path)\n", |
| 292 | + " try:\n", |
| 293 | + " trans_dll = ctypes.CDLL(dll_path)\n", |
| 294 | + " except OSError as e:\n", |
| 295 | + " raise RuntimeError(f\"Failed to load DLL: {e}\")\n", |
302 | 296 | "\n",
|
303 |
| - " # Define argument and return types for _InitSkTrans\n", |
| 297 | + " # Define argument and return types\n", |
304 | 298 | " _InitSkTrans = trans_dll._InitSkTrans\n",
|
305 | 299 | " _InitSkTrans.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_short), ctypes.POINTER(ctypes.c_short)]\n",
|
306 | 300 | " _InitSkTrans.restype = None\n",
|
307 | 301 | "\n",
|
308 |
| - " # Define argument and return types for _GeoTrans\n", |
309 |
| - " _GeoTrans = trans_dll._GeoTrans\n", |
310 |
| - " _GeoTrans.argtypes = [\n", |
311 |
| - " ctypes.POINTER(ctypes.c_short), ctypes.POINTER(ctypes.c_short),\n", |
312 |
| - " ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double),\n", |
313 |
| - " ctypes.POINTER(ctypes.c_short), ctypes.POINTER(ctypes.c_short),\n", |
314 |
| - " ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double),\n", |
315 |
| - " ctypes.POINTER(ctypes.c_short)\n", |
316 |
| - " ]\n", |
317 |
| - " _GeoTrans.restype = None\n", |
318 |
| - "\n", |
319 |
| - " # Initialize the transformation\n", |
320 | 302 | " href = href_file.encode('utf-8')\n",
|
321 | 303 | " sLen = ctypes.c_short(len(href))\n",
|
322 | 304 | " sErr = ctypes.c_short(0)\n",
|
323 |
| - " _InitSkTrans(href, ctypes.byref(sLen), ctypes.byref(sErr))\n", |
| 305 | + "\n", |
| 306 | + " print(\"Initializing transformation...\")\n", |
| 307 | + " try:\n", |
| 308 | + " _InitSkTrans(href, ctypes.byref(sLen), ctypes.byref(sErr))\n", |
| 309 | + " except Exception as e:\n", |
| 310 | + " print(f\"Error during initialization: {e}\")\n", |
| 311 | + " \n", |
324 | 312 | " if sErr.value != 0:\n",
|
325 |
| - " raise RuntimeError(\"Failed to initialize transformation.\")\n", |
| 313 | + " print(f\"sErr value: {sErr.value}\") # Log the error code\n", |
| 314 | + " raise RuntimeError(f\"Failed to initialize transformation. Error Code: {sErr.value}\")\n", |
| 315 | + "\n", |
| 316 | + " return trans_dll, _InitSkTrans, trans_dll._GeoTrans\n", |
326 | 317 | "\n",
|
327 |
| - " return trans_dll, _InitSkTrans, _GeoTrans\n", |
328 | 318 | "\n",
|
329 | 319 | "def transform_aalesund_to_euref(x, y, _GeoTrans, slSys1, slZone1, slSys2, slZone2):\n",
|
330 | 320 | " \"\"\"\n",
|
|
359 | 349 | " )\n",
|
360 | 350 | "\n",
|
361 | 351 | " if slErr.value != 0:\n",
|
362 |
| - " raise RuntimeError(\"Coordinate transformation failed.\")\n", |
| 352 | + " raise RuntimeError(f\"Failed to initialize transformation. Error Code: {sErr.value}\")\n", |
363 | 353 | "\n",
|
364 | 354 | " # Swap to return (Easting, Northing) if DLL returns (Northing, Easting)\n",
|
365 | 355 | " return y2.value, x2.value\n",
|
|
406 | 396 | "\n",
|
407 | 397 | "def main():\n",
|
408 | 398 | " # Define paths\n",
|
409 |
| - " sos_path = \"../datasets/aalesund/1504209/209.sos\"\n", |
410 |
| - " image_path = \"../datasets/aalesund/1504209/209.jpg\"\n", |
411 |
| - " dll_path = r\"C:\\Users\\siver\\ScanAI\\sos_coordinate_extracting\\skt2_1507-1504_1.dll\"\n", |
412 |
| - " href_file = r\"C:\\Users\\siver\\ScanAI\\sos_coordinate_extracting\\HREF2018B_NN2000_EUREF89.bin\"\n", |
| 399 | + " sos_path = \"../datasets/aalesund/1504201/201.sos\"\n", |
| 400 | + " image_path = \"../datasets/aalesund/1504201/201.jpg\"\n", |
| 401 | + " dll_path = r\"skt2_1507-1504_1.dll\"\n", |
| 402 | + " href_file = r\"HREF2018B_NN2000_EUREF89.bin\"\n", |
413 | 403 | "\n",
|
414 | 404 | " # Parse the SOS file\n",
|
415 | 405 | " koordsys, coords = parse_sos_file(sos_path)\n",
|
|
480 | 470 | ],
|
481 | 471 | "metadata": {
|
482 | 472 | "kernelspec": {
|
483 |
| - "display_name": "Python 3.12 (32-bit)", |
| 473 | + "display_name": "Python 3.12 (32bit)", |
484 | 474 | "language": "python",
|
485 | 475 | "name": "py32"
|
486 | 476 | },
|
|
0 commit comments