{"id":1379,"date":"2026-10-23T07:39:58","date_gmt":"2026-10-23T07:39:58","guid":{"rendered":"https:\/\/helpwithmygisassignment.com\/blog\/?p=1379"},"modified":"2026-10-23T07:39:58","modified_gmt":"2026-10-23T07:39:58","slug":"segment-anything-model-sam-qgis-building-extraction","status":"publish","type":"post","link":"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/","title":{"rendered":"Segment Anything Model (SAM) for Automated Building Extraction in QGIS"},"content":{"rendered":"<div><\/div>\n<div>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_89 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Segment_Anything_Model_SAM_for_Automated_Building_Extraction_in_QGIS\" >Segment Anything Model (SAM) for Automated Building Extraction in QGIS<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Introduction\" >Introduction<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#1_Prerequisites_and_Setup\" >1. Prerequisites and Setup<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#11_Required_software_and_data\" >1.1 Required software and data<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Recommended_image_characteristics\" >Recommended image characteristics<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#12_Install_the_QGIS_plugin\" >1.2 Install the QGIS plugin<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#13_Configure_the_Python_environment\" >1.3 Configure the Python environment<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#2_Configure_CUDA_CPU_and_Model_Weights\" >2. Configure CUDA, CPU, and Model Weights<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#21_CUDA_GPU_configuration\" >2.1 CUDA GPU configuration<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#22_CPU_configuration\" >2.2 CPU configuration<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#23_Obtain_compatible_model_weights\" >2.3 Obtain compatible model weights<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#3_Load_High-Resolution_Imagery_into_QGIS\" >3. Load High-Resolution Imagery into QGIS<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_1_Add_the_orthophoto_or_satellite_image\" >Step 1: Add the orthophoto or satellite image<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_2_Prepare_a_manageable_processing_area\" >Step 2: Prepare a manageable processing area<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Recommended_practice\" >Recommended practice<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#4_Initialize_the_SAM_Model_on_the_Input_Raster\" >4. Initialize the SAM Model on the Input Raster<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_3_Open_the_SamGeo_segmentation_panel\" >Step 3: Open the SamGeo segmentation panel<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_4_Select_and_initialize_the_model\" >Step 4: Select and initialize the model<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_5_Assign_the_input_image\" >Step 5: Assign the input image<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#5_Segment_Individual_Buildings_with_Prompts\" >5. Segment Individual Buildings with Prompts<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_6_Use_foreground_and_background_points\" >Step 6: Use foreground and background points<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#When_point_prompts_work_best\" >When point prompts work best<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_7_Use_a_bounding_box\" >Step 7: Use a bounding box<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_8_Segment_additional_feature_types\" >Step 8: Segment additional feature types<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_9_Try_text_prompts_where_supported\" >Step 9: Try text prompts where supported<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#6_Run_Batch_Segmentation_for_Many_Buildings\" >6. Run Batch Segmentation for Many Buildings<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#7_Save_Segmentation_Results_as_Raster_or_Vector_Data\" >7. Save Segmentation Results as Raster or Vector Data<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_10_Save_the_mask\" >Step 10: Save the mask<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#8_Convert_Raster_Masks_into_Editable_Building_Polygons\" >8. Convert Raster Masks into Editable Building Polygons<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_11_Polygonize_the_raster_mask\" >Step 11: Polygonize the raster mask<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Handle_background_values_correctly\" >Handle background values correctly<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Why_polygonization_matters\" >Why polygonization matters<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-33\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#9_Clean_and_Validate_the_Vector_Building_Footprints\" >9. Clean and Validate the Vector Building Footprints<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-34\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_12_Fix_invalid_geometries\" >Step 12: Fix invalid geometries<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-35\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_13_Separate_multipart_features\" >Step 13: Separate multipart features<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-36\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_14_Remove_small_false_positives\" >Step 14: Remove small false positives<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-37\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_15_Simplify_overly_complex_boundaries\" >Step 15: Simplify overly complex boundaries<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-38\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_16_Smooth_only_where_appropriate\" >Step 16: Smooth only where appropriate<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-39\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Step_17_Inspect_and_correct_false_positives\" >Step 17: Inspect and correct false positives<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-40\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#10_Calculate_Building_Attributes_and_Save_the_Final_Dataset\" >10. Calculate Building Attributes and Save the Final Dataset<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-41\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#11_Optional_Automate_the_Workflow_with_the_QGIS_Python_Console\" >11. Optional: Automate the Workflow with the QGIS Python Console<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-42\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Important_script_notes\" >Important script notes<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-43\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#12_Manual_Digitizing_vs_SAM-Assisted_Extraction\" >12. Manual Digitizing vs SAM-Assisted Extraction<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-44\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#121_How_to_evaluate_accuracy_objectively\" >12.1 How to evaluate accuracy objectively<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-45\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#13_Troubleshooting_Common_Problems\" >13. Troubleshooting Common Problems<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-46\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#The_model_fails_to_load\" >The model fails to load<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-47\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Segmentation_is_slow\" >Segmentation is slow<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-48\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#The_mask_includes_an_entire_road_or_neighboring_roof\" >The mask includes an entire road or neighboring roof<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-49\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#No_masks_are_generated\" >No masks are generated<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-50\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#The_vector_layer_is_shifted_or_has_the_wrong_CRS\" >The vector layer is shifted or has the wrong CRS<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-51\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"Segment_Anything_Model_SAM_for_Automated_Building_Extraction_in_QGIS\"><\/span>Segment Anything Model (SAM) for Automated Building Extraction in QGIS<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"Introduction\"><\/span>Introduction<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-1525\" src=\"https:\/\/helpwithmygisassignment.com\/blog\/wp-content\/uploads\/2026\/10\/Gemini_Generated_Image_r2xukpr2xukpr2xu-1024x572.jpg\" alt=\"Segment Anything Model SAM QGIS building extraction interface showing AI-generated building footprint masks on satellite imagery\" width=\"1024\" height=\"572\" srcset=\"https:\/\/helpwithmygisassignment.com\/blog\/wp-content\/uploads\/2026\/10\/Gemini_Generated_Image_r2xukpr2xukpr2xu-1024x572.jpg 1024w, https:\/\/helpwithmygisassignment.com\/blog\/wp-content\/uploads\/2026\/10\/Gemini_Generated_Image_r2xukpr2xukpr2xu-300x167.jpg 300w, https:\/\/helpwithmygisassignment.com\/blog\/wp-content\/uploads\/2026\/10\/Gemini_Generated_Image_r2xukpr2xukpr2xu-768x429.jpg 768w, https:\/\/helpwithmygisassignment.com\/blog\/wp-content\/uploads\/2026\/10\/Gemini_Generated_Image_r2xukpr2xukpr2xu.jpg 1376w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>Using the <b data-path-to-node=\"2,0,1,0,1,0\" data-index-in-node=\"11\">Segment Anything Model SAM QGIS building extraction<\/b> workflow significantly streamlines automated feature digitizing and <a href=\"https:\/\/helpwithmygisassignment.com\/blog\/building-real-time-spatial-dashboards-in-qgis-with-geonode-and-postgis\/\">spatial analysis<\/a> compared to manual vector tracing. Building footprint extraction is one of the most time-consuming tasks in remote sensing and GIS. In conventional workflows, an analyst examines aerial imagery, traces building boundaries manually, edits vertices, and saves the resulting polygons into a vector layer. For a large urban area containing thousands of buildings, this process can require substantial time and repetitive editing.<\/p>\n<p>Meta&#8217;s Segment Anything Model (SAM) introduces a different workflow. Rather than tracing every boundary manually, an analyst provides prompts\u2014such as foreground points, background points, or bounding boxes\u2014and the model predicts image masks corresponding to the selected objects.<\/p>\n<p>In QGIS, this creates a practical GeoAI workflow for AI satellite image segmentation and automated feature digitizing. The output can be converted into vector polygons and refined using conventional GIS processing tools.<\/p>\n<p>Two relevant plugins are available through the QGIS ecosystem:<\/p>\n<ul>\n<li>\n<div>\n<div>\n<p>SamGeo supports interactive point prompts, bounding-box prompts, text-based segmentation in supported model versions, and raster or vector outputs.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Geo SAM provides model management and supports multiple SAM model families, including SAM, SAM 2, SAM 2.1, and SAM 3.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<p>This tutorial uses SamGeo for the primary workflow because its documented interface includes point prompting, box prompting, model selection, and output export.<\/p>\n<p>The objective is to extract building footprints from a high-resolution orthophoto, convert the segmentation masks into editable polygons, and clean the resulting vector layer.<\/p>\n<blockquote><p>Important: SAM is a general-purpose segmentation model, not a guarantee of building detection. It can identify plausible image objects without knowing that they are buildings. Roofs, paved areas, shadows, pools, and vegetation may therefore be segmented incorrectly. Human validation remains essential.<\/p><\/blockquote>\n<div><\/div>\n<h1><span class=\"ez-toc-section\" id=\"1_Prerequisites_and_Setup\"><\/span>1. Prerequisites and Setup<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"11_Required_software_and_data\"><\/span>1.1 Required software and data<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before beginning, prepare the following:<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<th>Requirement<\/th>\n<th>Purpose<\/th>\n<\/tr>\n<tr>\n<td>QGIS 3.22 or later<\/td>\n<td>Loads imagery and manages the GIS processing workflow; verify compatibility with your chosen plugin release.<\/td>\n<\/tr>\n<tr>\n<td>High-resolution GeoTIFF or orthophoto<\/td>\n<td>Input for building segmentation.<\/td>\n<\/tr>\n<tr>\n<td>SamGeo or Geo SAM plugin<\/td>\n<td>Provides the SAM interface inside QGIS.<\/td>\n<\/tr>\n<tr>\n<td>Compatible Python and PyTorch environment<\/td>\n<td>Runs the model and its dependencies.<\/td>\n<\/tr>\n<tr>\n<td>SAM model weights<\/td>\n<td>Supplies the trained model parameters.<\/td>\n<\/tr>\n<tr>\n<td>GPU or CPU<\/td>\n<td>Runs segmentation inference.<\/td>\n<\/tr>\n<tr>\n<td>GeoPackage output<\/td>\n<td>Stores editable building polygons and their attributes.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>The SamGeo plugin documentation specifies QGIS 3.22 or later and Python 3.10 or later for its current documented setup. Its model and dependency requirements vary with the SAM version selected.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<h3><span class=\"ez-toc-section\" id=\"Recommended_image_characteristics\"><\/span>Recommended image characteristics<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>For building extraction, use orthorectified, high-resolution imagery with clearly visible roof boundaries.<\/p>\n<p>Suitable sources include aerial orthophotos, UAV orthomosaics, and high-resolution commercial or government satellite imagery.<\/p>\n<p>The appropriate resolution depends on the size of the buildings. Images at sub-meter resolution are generally more useful for individual roof boundaries than medium-resolution satellite imagery, but image quality, viewing angle, shadows, and roof contrast all influence segmentation quality.<\/p>\n<p>A 10 m Sentinel-2 image, for example, is generally unsuitable for reliably delineating individual small buildings because many roofs occupy only a few pixels.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"12_Install_the_QGIS_plugin\"><\/span>1.2 Install the QGIS plugin<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Open QGIS and follow these steps:<\/p>\n<ol>\n<li>\n<div>\n<div>\n<p>Go to Plugins \u2192 Manage and Install Plugins.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Select the All tab.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Search for <code>SamGeo<\/code>.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Select the compatible release and click Install Plugin.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Restart QGIS if requested.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Look for the SamGeo toolbar icon or open Raster \u2192 SamGeo \u2192 SamGeo Segmentation.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p>The repository documents these plugin access paths.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<p>You can also install Geo SAM through the same Plugin Manager by searching for <code>Geo SAM<\/code>. Its official QGIS plugin listing documents in-plugin model management and dependency support.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<div>\n<div>\n<p>Choose your plugin version carefully<\/p>\n<\/div>\n<p>SamGeo&#8217;s QGIS repository currently lists stable and experimental releases separately. At the time of writing, the listed stable release is 1.2.0 and the experimental release is 1.4.0. If a particular model or text-prompt control is missing, check the release notes before assuming the installation has failed.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<p>Plugin repository: <a href=\"https:\/\/plugins.qgis.org\/plugins\/samgeo\/?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noopener\">SamGeo<\/a> \u00b7 <a href=\"https:\/\/plugins.qgis.org\/plugins\/GeoSAM\/?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noopener\">Geo SAM<\/a><\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"13_Configure_the_Python_environment\"><\/span>1.3 Configure the Python environment<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Installing the QGIS plugin does not always mean that every deep-learning dependency is installed in the Python environment running QGIS.<\/p>\n<p>If the plugin opens correctly and can load its models, you can proceed to the next section. If it reports a missing <code>samgeo<\/code>, <code>torch<\/code>, or related module, use the setup instructions for your plugin release and operating system.<\/p>\n<p>The SamGeo maintainers document a Conda-based environment for installing QGIS and the geospatial SAM package. On macOS or Linux, their documented starting point is:<\/p>\n<div>\n<div>\n<pre dir=\"ltr\"><code># Create an isolated Python environment\r\nconda create -n geo python=3.12\r\n\r\n# Activate the environment\r\nconda activate geo\r\n\r\n# Install QGIS and the base geospatial SAM package\r\nconda install -c conda-forge qgis segment-geospatial\r\n\r\n# Install the additional dependencies for SAM 3 support\r\npip install -U \"segment-geospatial[samgeo3]\"<\/code><\/pre>\n<\/div>\n<\/div>\n<p>The final command installs optional dependencies for SAM 3. You do not necessarily need the SAM 3 extras to run an older supported model. Consult the <a href=\"https:\/\/github.com\/opengeos\/qgis-samgeo-plugin?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noopener\">SamGeo plugin documentation<\/a> for the installation instructions matching your version.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<p>Windows users: Deep-learning dependencies can be particularly sensitive to mismatched Python, PyTorch, CUDA, and QGIS environments. The plugin maintainers publish Windows-specific instructions for their supported SAM 3 setup. Avoid installing packages into an arbitrary system Python and assuming QGIS will automatically use them.<\/p>\n<div><\/div>\n<h1><span class=\"ez-toc-section\" id=\"2_Configure_CUDA_CPU_and_Model_Weights\"><\/span>2. Configure CUDA, CPU, and Model Weights<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>SAM inference can run on a CPU, but a compatible GPU can substantially reduce the time required for large imagery and repeated interactive prompts.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"21_CUDA_GPU_configuration\"><\/span>2.1 CUDA GPU configuration<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>For an NVIDIA GPU, the requirements include a compatible PyTorch build and functioning CUDA support.<\/p>\n<p>The practical setup process is:<\/p>\n<ol>\n<li>\n<div>\n<div>\n<p>Confirm that the GPU and NVIDIA driver are supported by your chosen PyTorch installation.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Install PyTorch with a compatible CUDA build in the environment used by QGIS.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Restart QGIS using that environment.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Open the SamGeo panel.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>In the Model tab, choose the model version.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Set the device to <code>cuda<\/code> or <code>auto<\/code>.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Click Load Model.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p>The SamGeo interface documents <code>auto<\/code>, <code>cuda<\/code>, and <code>cpu<\/code> device selection.<\/p>\n<div><\/div>\n<p>You can also inspect CUDA availability from the Python environment that runs QGIS:<\/p>\n<div>\n<div>\n<pre dir=\"ltr\"><code># Run this in the QGIS Python Console if torch is installed.import torchprint(\"PyTorch version:\", torch.__version__)print(\"CUDA available:\", torch.cuda.is_available())if torch.cuda.is_available():    print(\"GPU:\", torch.cuda.get_device_name(0))<\/code><\/pre>\n<\/div>\n<div><\/div>\n<\/div>\n<p>If <code>torch.cuda.is_available()<\/code> returns <code>False<\/code>, choosing <code>cuda<\/code> in the plugin will not make the GPU available. Resolve the environment or driver issue, or switch to CPU.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"22_CPU_configuration\"><\/span>2.2 CPU configuration<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you do not have a compatible NVIDIA GPU:<\/p>\n<ol>\n<li>\n<div>\n<div>\n<p>Open the SamGeo panel.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Select the desired SAM model.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Choose <code>cpu<\/code> as the device.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Load the model.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Test it on a small image subset before processing a larger study area.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p>CPU inference is often adequate for learning the workflow or segmenting selected buildings, although repeated interactive prompts can be slower.<\/p>\n<p>For large scenes, crop the imagery to a manageable area, avoid unnecessarily large input images, and use batch processing only after testing representative objects.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"23_Obtain_compatible_model_weights\"><\/span>2.3 Obtain compatible model weights<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>SAM models use version-specific weights. A checkpoint for the original SAM model should not be assumed to work with SAM 2 or SAM 3.<\/p>\n<p>For the original SAM implementation, Meta provides several model sizes:<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<th>Model<\/th>\n<th>Checkpoint filename<\/th>\n<\/tr>\n<tr>\n<td>ViT-B<\/td>\n<td><code>sam_vit_b_01ec64.pth<\/code><\/td>\n<\/tr>\n<tr>\n<td>ViT-L<\/td>\n<td><code>sam_vit_l_0b3195.pth<\/code><\/td>\n<\/tr>\n<tr>\n<td>ViT-H<\/td>\n<td><code>sam_vit_h_4b8939.pth<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>These are the official checkpoint filenames for the original SAM model.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<p>Use the plugin&#8217;s model manager or its documented download mechanism whenever available. This reduces the chance of choosing a checkpoint incompatible with the selected model family.<\/p>\n<p>SAM 3 note: SamGeo documents that SAM 3 setup requires Hugging Face authentication and access to the model. You may need to sign in and request access before the plugin can download or load it.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<p>For this building-extraction workflow, SAM 1 or SAM 2 with point and box prompts may be sufficient. Text prompting is an additional option in supported model versions, not a requirement for extracting buildings.<\/p>\n<div><\/div>\n<h1><span class=\"ez-toc-section\" id=\"3_Load_High-Resolution_Imagery_into_QGIS\"><\/span>3. Load High-Resolution Imagery into QGIS<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"Step_1_Add_the_orthophoto_or_satellite_image\"><\/span>Step 1: Add the orthophoto or satellite image<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In QGIS:<\/p>\n<ol>\n<li>\n<div>\n<div>\n<p>Select Layer \u2192 Add Layer \u2192 Add Raster Layer.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Browse to the GeoTIFF or orthophoto.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Click Add.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Zoom to the raster layer.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Inspect the image to confirm that individual roofs are visible.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p>Check the raster properties by right-clicking the image layer and selecting Properties.<\/p>\n<p>Under the Information section, inspect:<\/p>\n<ul>\n<li>\n<div>\n<div>\n<p>Coordinate reference system (CRS).<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Raster width and height.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Number of bands.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Pixel size.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Data type and NoData information.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<p>SAM operates on image pixels, so the visible image detail is central to segmentation quality. Keep the raster&#8217;s geographic reference intact for spatial outputs.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_2_Prepare_a_manageable_processing_area\"><\/span>Step 2: Prepare a manageable processing area<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Do not start by passing a very large regional mosaic into an interactive segmentation workflow.<\/p>\n<p>Instead:<\/p>\n<ol>\n<li>\n<div>\n<div>\n<p>Identify a representative block or neighborhood.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Open the Processing Toolbox.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Search for Clip Raster by Extent or Clip Raster by Mask Layer.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Select the input imagery.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Set the target extent or study-area polygon.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Save the result as a new GeoTIFF.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p>A cropped raster is useful for three reasons:<\/p>\n<ul>\n<li>\n<div>\n<div>\n<p>It reduces the amount of imagery being processed.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>It allows you to inspect the result at a practical map scale.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>It makes model failures easier to diagnose.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<p>For a large city, divide the project into manageable blocks and keep a record of each processed extent.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Recommended_practice\"><\/span>Recommended practice<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>For an initial test, choose an area that contains different roof types, building sizes, roof colors, and some difficult cases such as tree shadows or buildings close to roads.<\/p>\n<p>A small but varied test area is more useful for evaluating the model than choosing only the clearest roofs.<\/p>\n<div><\/div>\n<h1><span class=\"ez-toc-section\" id=\"4_Initialize_the_SAM_Model_on_the_Input_Raster\"><\/span>4. Initialize the SAM Model on the Input Raster<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"Step_3_Open_the_SamGeo_segmentation_panel\"><\/span>Step 3: Open the SamGeo segmentation panel<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Use the SamGeo toolbar icon or navigate to:<\/p>\n<p>Raster \u2192 SamGeo \u2192 SamGeo Segmentation<\/p>\n<p>The panel is documented as having tabs for model selection, text prompts, interactive prompts, batch work, and output. Exact labels can vary between releases.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Step_4_Select_and_initialize_the_model\"><\/span>Step 4: Select and initialize the model<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In the Model tab:<\/p>\n<ol>\n<li>\n<div>\n<div>\n<p>Select the SAM model version.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Select the backend, where available.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Set the device to <code>auto<\/code>, <code>cuda<\/code>, or <code>cpu<\/code>.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Set the confidence threshold if the selected model supports it.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Enable interactive mode for point and box prompts.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Click Load Model.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p>Allow the model to finish initializing before attempting segmentation.<\/p>\n<p>The model may download weights or perform initial preprocessing the first time it loads. Later runs may reuse the downloaded weights and cached model files.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_5_Assign_the_input_image\"><\/span>Step 5: Assign the input image<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The SamGeo interface supports selecting a raster layer from the layer dropdown and clic<\/p>\n<p>Select the cropped orthophoto created in Step 2.<\/p>\n<p>After assigning the image, inspect the map and confirm that the input matches the scene you intend to segment. Do not assume the plugin automatically crops the image to the current QGIS map-canvas extent; use a dedicated subset when you need precise control over processing boundaries.<\/p>\n<div><\/div>\n<h1><span class=\"ez-toc-section\" id=\"5_Segment_Individual_Buildings_with_Prompts\"><\/span>5. Segment Individual Buildings with Prompts<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-1526\" src=\"https:\/\/helpwithmygisassignment.com\/blog\/wp-content\/uploads\/2026\/10\/Gemini_Generated_Image_rk5vaark5vaark5v-1024x559.jpg\" alt=\"Segment Anything Model SAM QGIS building extraction point prompts and bounding boxes on a raster orthophoto\" width=\"1024\" height=\"559\" srcset=\"https:\/\/helpwithmygisassignment.com\/blog\/wp-content\/uploads\/2026\/10\/Gemini_Generated_Image_rk5vaark5vaark5v-1024x559.jpg 1024w, https:\/\/helpwithmygisassignment.com\/blog\/wp-content\/uploads\/2026\/10\/Gemini_Generated_Image_rk5vaark5vaark5v-300x164.jpg 300w, https:\/\/helpwithmygisassignment.com\/blog\/wp-content\/uploads\/2026\/10\/Gemini_Generated_Image_rk5vaark5vaark5v-768x419.jpg 768w, https:\/\/helpwithmygisassignment.com\/blog\/wp-content\/uploads\/2026\/10\/Gemini_Generated_Image_rk5vaark5vaark5v.jpg 1408w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>Prompt-based segmentation is where the main advantage of SAM becomes apparent. Instead of tracing every roof boundary vertex by vertex, you indicate the object of interest and let the model infer a mask.<\/p>\n<p>There are two primary workflows: point prompts and bounding-box prompts.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_6_Use_foreground_and_background_points\"><\/span>Step 6: Use foreground and background points<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Open the plugin&#8217;s Interactive tab.<\/p>\n<p>Follow this sequence:<\/p>\n<ol>\n<li>\n<div>\n<div>\n<p>Select Add Foreground Points.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Click inside the roof you want to extract.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Add further foreground points if the roof has several visually distinct sections.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Select Add Background Points.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Click outside the building on a road, tree, shadow, or nearby roof that should not be included.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Click Segment by Points.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Inspect the predicted mask.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Add or reposition prompts if necessary, then run the segmentation again.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p>The plugin documentation confirms that positive and negative point prompts can be used in the interactive workflow.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<div>\n<p>Prompting strategy for buildings<\/p>\n<div>\n<div>\n<p>Foreground<\/p>\n<\/div>\n<div>\n<p>Place the point on the roof.<\/p>\n<p>Avoid placing it on a roof shadow, adjacent tree, or background pavement. For a large roof with multiple wings, try more than one positive point.<\/p>\n<\/div>\n<\/div>\n<div><\/div>\n<div>\n<div>\n<p>Background<\/p>\n<\/div>\n<div>\n<p>Place a negative point outside the intended building.<\/p>\n<p>Use it near a boundary that the mask has mistakenly crossed, such as a roof beside a paved parking area.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<h3><span class=\"ez-toc-section\" id=\"When_point_prompts_work_best\"><\/span>When point prompts work best<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Points are particularly effective when the building is visually distinct but irregular in shape, or where one roof touches a neighboring object and requires more precise guidance.<\/p>\n<p>For example, a large industrial roof may need positive points in different sections, while a negative point near a row of trees may help the model exclude surrounding vegetation.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_7_Use_a_bounding_box\"><\/span>Step 7: Use a bounding box<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>For a clearly identifiable building, a box can be faster than multiple points.<\/p>\n<p>In the Interactive tab:<\/p>\n<ol>\n<li>\n<div>\n<div>\n<p>Click Draw Box.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Draw a rectangle around the building.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Include the full roof footprint while avoiding unrelated structures.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Click Segment by Box.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Inspect the predicted result.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Adjust the box or switch to point prompts if necessary.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p>SamGeo documents this exact box-based workflow.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<p>Bounding boxes are useful for buildings with a clear separation from their surroundings. They can be less reliable where multiple connected roofs, dense tree canopies, or strong shadows create ambiguous boundaries.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_8_Segment_additional_feature_types\"><\/span>Step 8: Segment additional feature types<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The same prompting workflow can be applied to other objects, although the results must be inspected carefully.<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<th>Feature<\/th>\n<th>Recommended approach<\/th>\n<th>Common difficulty<\/th>\n<\/tr>\n<tr>\n<td>Buildings<\/td>\n<td>Positive point or tight bounding box<\/td>\n<td>Shadows and adjacent roofs<\/td>\n<\/tr>\n<tr>\n<td>Swimming pools<\/td>\n<td>Positive point within the pool<\/td>\n<td>Similar-colored roofs or water surfaces<\/td>\n<\/tr>\n<tr>\n<td>Solar panels<\/td>\n<td>Tight box plus positive point<\/td>\n<td>Small panels can blend into roof texture<\/td>\n<\/tr>\n<tr>\n<td>Forest patches<\/td>\n<td>Positive points in vegetation and negative points outside<\/td>\n<td>Mixed canopy boundaries and shadows<\/td>\n<\/tr>\n<tr>\n<td>Roadside structures<\/td>\n<td>Box or multiple points<\/td>\n<td>Buildings touching paved surfaces<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>SAM&#8217;s task is to identify image objects and boundaries, not to guarantee the correct semantic class. A mask around a rectangular parking lot may look convincing while still being a false building detection.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_9_Try_text_prompts_where_supported\"><\/span>Step 9: Try text prompts where supported<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Some current SamGeo model versions include text-based segmentation. In the Text tab, enter a prompt such as:<\/p>\n<div>\n<div>\n<pre dir=\"ltr\"><code>building<\/code><\/pre>\n<\/div>\n<\/div>\n<p>Then click Segment by Text.<\/p>\n<p>Other possible prompts include <code>tree<\/code>, <code>road<\/code>, or <code>water<\/code>, depending on the model and the visual characteristics of the imagery.<\/p>\n<p>The plugin documentation identifies text-based segmentation as a feature of its supported SAM versions, particularly the SamGeo3\/SAM 3 workflow.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<p>Do not assume text prompts will work in every SAM release or backend. If your selected model lacks text prompting, use point or box prompts instead.<\/p>\n<div><\/div>\n<h1><span class=\"ez-toc-section\" id=\"6_Run_Batch_Segmentation_for_Many_Buildings\"><\/span>6. Run Batch Segmentation for Many Buildings<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>Interactive prompts are useful for isolated objects, but city-scale building extraction requires a more systematic approach.<\/p>\n<p>One option is to prepare a point layer containing approximate building centroids. These could be generated from existing building records, manually placed seeds, or another detection process.<\/p>\n<p>In the SamGeo Batch tab:<\/p>\n<ol>\n<li>\n<div>\n<div>\n<p>Select the point vector layer or browse to a point file.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Specify its CRS if the plugin cannot determine it automatically.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Configure minimum or maximum object size filters if supported.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Choose an output raster path if required.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Click Run Batch Segmentation.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p>The plugin documentation states that batch point segmentation uses each input point to generate a separate mask.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<p>This can accelerate extraction in areas where approximate building locations are already known.<\/p>\n<p>However, batch prompts are not equivalent to unrestricted automatic building detection. If a point falls on a tree, road, courtyard, or adjacent building, the resulting mask may be wrong.<\/p>\n<p>For a large region without seed points, consider generating candidate building locations with a building detector or another model first, then use SAM to refine the proposed boundaries.<\/p>\n<div><\/div>\n<h1><span class=\"ez-toc-section\" id=\"7_Save_Segmentation_Results_as_Raster_or_Vector_Data\"><\/span>7. Save Segmentation Results as Raster or Vector Data<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>After inspecting the masks, the next step is exporting them to a persistent GIS dataset.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_10_Save_the_mask\"><\/span>Step 10: Save the mask<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Open the plugin&#8217;s Output tab.<\/p>\n<ol>\n<li>\n<div>\n<div>\n<p>Choose the output format.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Select raster or vector output.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Specify the output path.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Click Save Masks.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p>The SamGeo interface documents export to raster or vector formats.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<p>For a new project, a GeoPackage is a practical vector target because it can store polygons and attributes in a single file, handles complex geometries better than the Shapefile format, and is convenient for subsequent QGIS editing.<\/p>\n<p>Use a descriptive filename, such as:<\/p>\n<div>\n<div>\n<pre dir=\"ltr\"><code>building_masks_raw.gpkg<\/code><\/pre>\n<\/div>\n<\/div>\n<p>If you save a GeoTIFF mask, use a name such as:<\/p>\n<div>\n<div>\n<pre dir=\"ltr\"><code>building_mask.tif<\/code><\/pre>\n<\/div>\n<\/div>\n<p>The raster route is useful when you need to inspect the binary mask, preserve intermediate outputs, or run additional raster-based filtering before vectorization.<\/p>\n<div><\/div>\n<h1><span class=\"ez-toc-section\" id=\"8_Convert_Raster_Masks_into_Editable_Building_Polygons\"><\/span>8. Convert Raster Masks into Editable Building Polygons<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>If the plugin exported a vector layer directly, skip to Step 12.<\/p>\n<p>If it exported a raster mask, use QGIS&#8217;s polygonization tools to convert mask regions into polygons.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_11_Polygonize_the_raster_mask\"><\/span>Step 11: Polygonize the raster mask<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Open the Processing Toolbox and search for:<\/p>\n<p>Polygonize (Raster to Vector)<\/p>\n<p>This is the GDAL polygonization workflow. Polygonization creates polygons representing connected regions of pixels with the same raster value.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<p>Configure the tool:<\/p>\n<ol>\n<li>\n<div>\n<div>\n<p>Select <code>building_mask.tif<\/code> as the input raster.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Select the correct raster band.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Choose a field to receive the raster value, usually <code>DN<\/code>.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Specify a GeoPackage output.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Run the algorithm.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p>The resulting polygon layer may contain both background and object regions, depending on how the mask is encoded.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Handle_background_values_correctly\"><\/span>Handle background values correctly<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>For a binary mask:<\/p>\n<ul>\n<li>\n<div>\n<div>\n<p><code>0<\/code> commonly represents background.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>A nonzero value represents the segmented area.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<p>Do not assume every polygon produced by polygonization is a building. Inspect the <code>DN<\/code> values in the attribute table, select the object class, and exclude the background.<\/p>\n<p>Where the tool allows a valid-data mask, you can configure it to process only the intended object pixels. Alternatively, use a raster calculator or another raster preprocessing step to represent background pixels as NoData before polygonization.<\/p>\n<p>Save the filtered output as:<\/p>\n<div>\n<div>\n<pre dir=\"ltr\"><code>building_footprints_initial.gpkg<\/code><\/pre>\n<\/div>\n<\/div>\n<h3><span class=\"ez-toc-section\" id=\"Why_polygonization_matters\"><\/span>Why polygonization matters<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>A binary raster mask contains pixel-based shapes. Polygonization converts the boundaries of connected mask regions into vector geometries that can be edited, queried, measured, styled, and stored in a spatial database.<\/p>\n<p>It does not automatically improve accuracy or remove false positives; those steps come next.<\/p>\n<div><\/div>\n<h1><span class=\"ez-toc-section\" id=\"9_Clean_and_Validate_the_Vector_Building_Footprints\"><\/span>9. Clean and Validate the Vector Building Footprints<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>The first SAM output should be treated as a draft segmentation layer rather than a final building inventory.<\/p>\n<p>False positives, touching roofs, holes, small fragments, and irregular pixel edges are common.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_12_Fix_invalid_geometries\"><\/span>Step 12: Fix invalid geometries<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In the Processing Toolbox, search for:<\/p>\n<p>Fix Geometries<\/p>\n<p>Run it on <code>building_footprints_initial<\/code> and save the result as:<\/p>\n<div>\n<div>\n<pre dir=\"ltr\"><code>building_footprints_fixed.gpkg<\/code><\/pre>\n<\/div>\n<\/div>\n<p>This helps correct invalid geometries produced during mask conversion and subsequent processing.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_13_Separate_multipart_features\"><\/span>Step 13: Separate multipart features<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Search for:<\/p>\n<p>Multipart to Singleparts<\/p>\n<p>Run the algorithm if features contain several disconnected polygons grouped in one multipart geometry.<\/p>\n<p>This is useful when you need a separate feature for each building footprint.<\/p>\n<p>Be careful: adjacent buildings may be merged into one connected mask. Separating multipart features will not automatically split two buildings that have already been joined into one polygon.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_14_Remove_small_false_positives\"><\/span>Step 14: Remove small false positives<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>SAM may identify small objects that resemble roofs, such as sheds, vehicles, rooftop equipment, or bright concrete surfaces.<\/p>\n<p>First, reproject the layer into an appropriate projected CRS for your study region so that the geometry measurements are in meaningful linear units.<\/p>\n<p>Then use Extract by Expression or Select by Expression to filter features by area.<\/p>\n<p>For example, where the projected CRS uses meters, you might test:<\/p>\n<div>\n<div>\n<pre dir=\"ltr\"><code>$area &gt;= 12<\/code><\/pre>\n<\/div>\n<\/div>\n<p>This selects polygons with an area of at least 12 square meters, subject to the project&#8217;s ellipsoid and measurement settings.<\/p>\n<p>Do not use 12 m\u00b2 as a universal building threshold. Choose a minimum area based on your smallest legitimate structure, image resolution, and intended mapping scale. Small homes, kiosks, and outbuildings may be valid objects.<\/p>\n<p>If the smallest meaningful structure is 8 m\u00b2, a 12 m\u00b2 threshold would remove valid buildings.<\/p>\n<p>A good practice is to add an area field and inspect its distribution before deciding on the threshold.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_15_Simplify_overly_complex_boundaries\"><\/span>Step 15: Simplify overly complex boundaries<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Pixel-derived polygons often contain many small vertices along roof edges. Simplification can reduce these vertices and make the dataset more manageable.<\/p>\n<p>In QGIS:<\/p>\n<ol>\n<li>\n<div>\n<div>\n<p>Open the Processing Toolbox.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Search for Simplify geometries.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Select the cleaned building layer.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Choose a simplification method.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Set a tolerance appropriate to the imagery resolution.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Save the result as a new layer.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p>QGIS supports distance-based simplification and alternative methods; its documentation explains that the tolerance controls how aggressively vertices are removed.<\/p>\n<p>For building footprints, use a conservative tolerance. Excessive simplification can remove narrow roof extensions or distort small buildings.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_16_Smooth_only_where_appropriate\"><\/span>Step 16: Smooth only where appropriate<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>QGIS also provides Smooth under the vector geometry tools.<\/p>\n<p>Smoothing adds vertices and rounds corners, potentially improving irregular boundaries but also changing geometry.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<p>For building extraction, apply smoothing selectively rather than automatically to every polygon.<\/p>\n<p>Most buildings have straight, angular roof edges. Aggressive smoothing may therefore make a footprint less accurate, not more accurate.<\/p>\n<p>For many urban building layers, gentle simplification followed by manual vertex correction is preferable to heavy smoothing.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_17_Inspect_and_correct_false_positives\"><\/span>Step 17: Inspect and correct false positives<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Create a comparison view with:<\/p>\n<ul>\n<li>\n<div>\n<div>\n<p>The original imagery.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>The raw mask or initial footprint layer.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>The cleaned footprint layer.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<p>Use transparent polygon fills and contrasting outlines so roof edges remain visible.<\/p>\n<p>Inspect the following cases carefully:<\/p>\n<ul>\n<li>\n<div>\n<div>\n<p>Buildings under tree canopy.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Adjacent buildings touching along their roofs.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Roofs partly hidden by shadows.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Large paved surfaces incorrectly segmented as roofs.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Bright vehicles or structures mistaken for small buildings.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Roof areas split into several fragments.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Several individual buildings combined into one polygon.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<p>Use QGIS&#8217;s editing tools to split, merge, reshape, or delete features where necessary.<\/p>\n<p>The final layer should be based on visual verification, not merely on the absence of processing errors.<\/p>\n<div><\/div>\n<h1><span class=\"ez-toc-section\" id=\"10_Calculate_Building_Attributes_and_Save_the_Final_Dataset\"><\/span>10. Calculate Building Attributes and Save the Final Dataset<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>A useful building inventory should contain more than geometry.<\/p>\n<p>Open the attribute table of your cleaned footprint layer and use the Field Calculator to add fields such as:<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<th>Field<\/th>\n<th>Example type<\/th>\n<th>Purpose<\/th>\n<\/tr>\n<tr>\n<td><code>building_id<\/code><\/td>\n<td>Integer or text<\/td>\n<td>Unique building identifier<\/td>\n<\/tr>\n<tr>\n<td><code>area_m2<\/code><\/td>\n<td>Decimal<\/td>\n<td>Building footprint area<\/td>\n<\/tr>\n<tr>\n<td><code>perimeter_m<\/code><\/td>\n<td>Decimal<\/td>\n<td>Polygon perimeter<\/td>\n<\/tr>\n<tr>\n<td><code>review_status<\/code><\/td>\n<td>Text<\/td>\n<td>Manual verification status<\/td>\n<\/tr>\n<tr>\n<td><code>source_method<\/code><\/td>\n<td>Text<\/td>\n<td>Segmentation method<\/td>\n<\/tr>\n<tr>\n<td><code>confidence<\/code><\/td>\n<td>Decimal, if available<\/td>\n<td>Confidence value from the actual output model, if provided<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>For a projected CRS in meters, use the following expressions where appropriate:<\/p>\n<p>Footprint area:<\/p>\n<div>\n<div>\n<pre dir=\"ltr\"><code>$area<\/code><\/pre>\n<\/div>\n<\/div>\n<p>Perimeter:<\/p>\n<div>\n<div>\n<pre dir=\"ltr\"><code>$perimeter<\/code><\/pre>\n<\/div>\n<\/div>\n<p>Check your project&#8217;s ellipsoid settings and geometry units before interpreting the result as square meters or meters.<\/p>\n<p>Finally, export the cleaned layer to a persistent GeoPackage:<\/p>\n<p>Right-click layer \u2192 Export \u2192 Save Features As\u2026<\/p>\n<p>Choose:<\/p>\n<ul>\n<li>\n<div>\n<div>\n<p>Format: GeoPackage<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>File: <code>building_footprints_final.gpkg<\/code><\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Layer name: <code>building_footprints<\/code><\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>CRS: the selected project or analysis CRS<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<p>Ensure the output includes the desired attributes, then load it back into QGIS and verify the result.<\/p>\n<div><\/div>\n<h1><span class=\"ez-toc-section\" id=\"11_Optional_Automate_the_Workflow_with_the_QGIS_Python_Console\"><\/span>11. Optional: Automate the Workflow with the QGIS Python Console<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>The graphical workflow is suitable for learning and processing selected areas. Once the workflow is stable, you can automate parts of the vector cleanup using the QGIS Processing framework.<\/p>\n<p>For example, the following script repairs the geometries and simplifies the resulting layer:<\/p>\n<div>\n<div>\n<pre dir=\"ltr\"><code>import processing# Replace this path with the vector layer produced by SAM.input_layer = \"\/path\/to\/building_footprints_initial.gpkg\"# Output pathsfixed_output = \"\/path\/to\/building_footprints_fixed.gpkg\"simplified_output = \"\/path\/to\/building_footprints_simplified.gpkg\"# Step 1: Repair invalid polygon geometries.processing.run(    \"native:fixgeometries\",    {        \"INPUT\": input_layer,        \"OUTPUT\": fixed_output    })# Step 2: Simplify geometries using a conservative tolerance.# Choose a tolerance in the units of the layer CRS.processing.run(    \"native:simplifygeometries\",    {        \"INPUT\": fixed_output,        \"METHOD\": 0,        \"TOLERANCE\": 0.15,        \"OUTPUT\": simplified_output    })print(\"Vector cleanup completed.\")<\/code><\/pre>\n<\/div>\n<div><\/div>\n<\/div>\n<h3><span class=\"ez-toc-section\" id=\"Important_script_notes\"><\/span>Important script notes<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>This script assumes that the input is a vector layer and that the layer CRS uses meters. The <code>0.15<\/code> tolerance is only an example; it should be adjusted according to the orthophoto&#8217;s resolution and the size of the smallest building.<\/p>\n<p>Automating geometry repair and simplification does not eliminate the need to review the extracted footprints. It simply makes the repeatable cleanup stages easier to execute.<\/p>\n<p>You can expand this processing script to include multipart separation, attribute creation, area filtering, and export. The model inference itself should follow the API of the SamGeo or Geo SAM version installed in your QGIS environment.<\/p>\n<div><\/div>\n<h1><span class=\"ez-toc-section\" id=\"12_Manual_Digitizing_vs_SAM-Assisted_Extraction\"><\/span>12. Manual Digitizing vs SAM-Assisted Extraction<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>SAM changes the interaction between the analyst and the image, but it does not remove all mapping work.<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<th>Criterion<\/th>\n<th>Manual tracing<\/th>\n<th>SAM-assisted extraction<\/th>\n<\/tr>\n<tr>\n<td>Initial operation<\/td>\n<td>Digitize vertices around each building<\/td>\n<td>Supply prompts and generate a mask<\/td>\n<\/tr>\n<tr>\n<td>Throughput<\/td>\n<td>Decreases as the building count grows<\/td>\n<td>Can be faster for repeated, clearly visible objects<\/td>\n<\/tr>\n<tr>\n<td>Boundary quality<\/td>\n<td>Depends on analyst skill and zoom level<\/td>\n<td>Depends on image quality, model behavior, and prompt placement<\/td>\n<\/tr>\n<tr>\n<td>Complex roofs<\/td>\n<td>Requires careful vertex placement<\/td>\n<td>May follow irregular boundaries, but can confuse touching objects<\/td>\n<\/tr>\n<tr>\n<td>False positives<\/td>\n<td>Less dependent on model behavior, but human mistakes remain possible<\/td>\n<td>Requires review of roads, shadows, vegetation, and other similar surfaces<\/td>\n<\/tr>\n<tr>\n<td>Batch processing<\/td>\n<td>Usually repetitive unless other automation is used<\/td>\n<td>Supports batch workflows where seeds or supported prompts are available<\/td>\n<\/tr>\n<tr>\n<td>Final editing<\/td>\n<td>Required for digitizing errors<\/td>\n<td>Still required for segmentation errors<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>SAM can reduce the amount of manual tracing needed, particularly when buildings have visible boundaries and the model produces useful masks from a small number of prompts.<\/p>\n<p>However, time savings and boundary precision are dataset-dependent. Do not claim that SAM will always be faster or more accurate than manual tracing without evaluating the actual imagery and workflow.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"121_How_to_evaluate_accuracy_objectively\"><\/span>12.1 How to evaluate accuracy objectively<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Select a representative sample of buildings and create carefully reviewed reference footprints.<\/p>\n<p>Then compare the SAM-derived polygons against the reference data.<\/p>\n<p>One useful measure is Intersection over Union (IoU):<\/p>\n<div><span data-math-source=\"IoU = \\frac{A \\cap R}{A \\cup R}\" data-math-display=\"true\">\\[ IoU = \\frac{A \\cap R}{A \\cup R} \\]<\/span><\/div>\n<p>where:<\/p>\n<ul>\n<li>\n<div>\n<div>\n<p><span data-math-source=\"A\" data-math-display=\"false\">\\(A\\)<\/span> is the area of the predicted footprint.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p><span data-math-source=\"R\" data-math-display=\"false\">\\(R\\)<\/span> is the area of the reference footprint.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p><span data-math-source=\"A \\cap R\" data-math-display=\"false\">\\(A \\cap R\\)<\/span> is their intersection.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p><span data-math-source=\"A \\cup R\" data-math-display=\"false\">\\(A \\cup R\\)<\/span> is their union.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<p>An IoU closer to 1 indicates greater spatial overlap between a predicted footprint and the reference footprint.<\/p>\n<p>For a fair comparison, record the time required to process the same test area using manual tracing and SAM-assisted extraction, including the time spent correcting errors. Also compare missed buildings, false detections, and boundary alignment.<\/p>\n<p>This gives you a defensible estimate of time efficiency and accuracy for your own geographic area instead of relying on general claims about AI performance.<\/p>\n<div><\/div>\n<h1><span class=\"ez-toc-section\" id=\"13_Troubleshooting_Common_Problems\"><\/span>13. Troubleshooting Common Problems<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"The_model_fails_to_load\"><\/span>The model fails to load<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Check that the required Python package is installed in the environment used by QGIS, verify that the selected model has compatible weights, and make sure sufficient memory is available.<\/p>\n<p>If CUDA fails, try a CPU test to distinguish a model or image problem from a GPU configuration problem. The SamGeo documentation recommends checking dependencies, GPU memory, and restarting QGIS when model loading fails.<\/p>\n<div>\n<div><\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Segmentation_is_slow\"><\/span>Segmentation is slow<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Start with a smaller raster subset. If an NVIDIA GPU is available, confirm that the CUDA-enabled PyTorch build is working and that the plugin is actually using the GPU.<\/p>\n<p>The SamGeo documentation also recommends reducing image resolution where appropriate and testing a different backend where supported.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"The_mask_includes_an_entire_road_or_neighboring_roof\"><\/span>The mask includes an entire road or neighboring roof<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Try a tighter box and add background points near the incorrect boundary.<\/p>\n<p>If the objects have almost identical visual characteristics or are touching, the model may not have enough information to separate them reliably. In that case, manual editing or a specialized building detector may be necessary.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"No_masks_are_generated\"><\/span>No masks are generated<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Check whether:<\/p>\n<ul>\n<li>\n<div>\n<div>\n<p>The raster was correctly assigned to the model.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>The image has sufficient spatial detail.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>The correct model and prompt mode are selected.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>The confidence threshold is appropriate.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Size filters are not excluding the desired objects.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<p>SAM&#8217;s segmentation behavior depends heavily on the prompt and the image itself.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"The_vector_layer_is_shifted_or_has_the_wrong_CRS\"><\/span>The vector layer is shifted or has the wrong CRS<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Verify that the input imagery is correctly georeferenced and that the segmentation output preserves its spatial reference.<\/p>\n<p>When exporting or polygonizing a raster mask, confirm that the output uses the source raster&#8217;s correct geotransform and CRS. Avoid assigning a different CRS simply to make the layer appear in the right location.<\/p>\n<div><\/div>\n<h1><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>The Segment Anything Model provides a practical way to combine foundation-model segmentation with established QGIS processing tools. For building footprint extraction, the essential workflow is to prepare suitable imagery, load a compatible model, guide it with point or box prompts, export masks, polygonize raster results where necessary, and clean the final polygons.<\/p>\n<p>The most reliable approach is SAM-assisted digitizing with GIS quality control, rather than assuming that every predicted mask is a valid building footprint.<\/p>\n<p>For individual objects and small survey areas, interactive prompts can significantly reduce repetitive tracing. For larger regions, batch prompts and carefully designed processing pipelines can improve throughput, provided that false positives and missed buildings are checked systematically.<\/p>\n<p>Once validated, the resulting GeoPackage can support building inventories, urban growth analysis, impervious-surface assessment, exposure mapping, and other . The final accuracy, however, will depend on the imagery, the model versio<span style=\"font-size: inherit;\">n, the prompt strategy, and the quality-control process\u2014not simply on whether SAM completed successfully.<\/span><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Segment Anything Model (SAM) for Automated Building Extraction in QGIS Introduction Using the Segment Anything Model SAM QGIS building extraction workflow significantly streamlines automated feature digitizing and spatial analysis compared to manual vector tracing. Building footprint extraction is one of the most time-consuming tasks in remote sensing and GIS. In conventional workflows, an analyst examines &#8230; <a title=\"Segment Anything Model (SAM) for Automated Building Extraction in QGIS\" class=\"read-more\" href=\"https:\/\/helpwithmygisassignment.com\/blog\/segment-anything-model-sam-qgis-building-extraction\/\" aria-label=\"Read more about Segment Anything Model (SAM) for Automated Building Extraction in QGIS\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":1526,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4],"tags":[],"class_list":["post-1379","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","category-gis-articles"],"_links":{"self":[{"href":"https:\/\/helpwithmygisassignment.com\/blog\/wp-json\/wp\/v2\/posts\/1379","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/helpwithmygisassignment.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/helpwithmygisassignment.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/helpwithmygisassignment.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/helpwithmygisassignment.com\/blog\/wp-json\/wp\/v2\/comments?post=1379"}],"version-history":[{"count":3,"href":"https:\/\/helpwithmygisassignment.com\/blog\/wp-json\/wp\/v2\/posts\/1379\/revisions"}],"predecessor-version":[{"id":1527,"href":"https:\/\/helpwithmygisassignment.com\/blog\/wp-json\/wp\/v2\/posts\/1379\/revisions\/1527"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/helpwithmygisassignment.com\/blog\/wp-json\/wp\/v2\/media\/1526"}],"wp:attachment":[{"href":"https:\/\/helpwithmygisassignment.com\/blog\/wp-json\/wp\/v2\/media?parent=1379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/helpwithmygisassignment.com\/blog\/wp-json\/wp\/v2\/categories?post=1379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/helpwithmygisassignment.com\/blog\/wp-json\/wp\/v2\/tags?post=1379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}