3737 14 ,
3838 "CONUS" ,
3939 # Backup URL
40- "https://data.kitware.com/api/v1/item/697cc601e7dea9be44ec5aee /download" ,
40+ "https://data.kitware.com/api/v1/item/6a05c0aef88b2b3dd9854751 /download" ,
4141 ),
4242 # Optional regions (disabled by default). Include via --locations.
4343 "AKCAN" : (
6464 "Puerto Rico" ,
6565 None ,
6666 ),
67+ "CONUS_OFFSHORE" : (
68+ "https://data.kitware.com/api/v1/item/6a05c0dbf88b2b3dd9854754/download" ,
69+ 24 ,
70+ "Offshore CONUS" ,
71+ None ,
72+ ),
6773}
6874
6975LOCATION_ID_TO_KEY = {str (config [1 ]): key for key , config in LOCATION_SOURCES .items ()}
@@ -122,7 +128,11 @@ def handle(self, *args, **options): # noqa: C901, PLR0912, PLR0915
122128 shapefiles = [LOCATION_SOURCES [location_key ] for location_key in selected_keys ]
123129
124130 for url , sample_frame_id , name , backup_url in shapefiles :
125- logger .info ("Downloading shapefile for Location %s..." , name )
131+ logger .info (
132+ "Downloading shapefile for Location %s with sample frame id %s" ,
133+ name ,
134+ sample_frame_id ,
135+ )
126136 with tempfile .TemporaryDirectory () as tmpdir :
127137 tmpdir = Path (tmpdir )
128138
@@ -167,9 +177,20 @@ def handle(self, *args, **options): # noqa: C901, PLR0912, PLR0915
167177 else :
168178 logger .warning ("Shapefile CRS unknown; assuming EPSG:4326" )
169179
180+ if "GRTS_ID" in gdf .columns :
181+ grts_id_col = "GRTS_ID"
182+ elif "grts_id" in gdf .columns :
183+ grts_id_col = "grts_id"
184+ logger .info ("GRTS_ID column not found; using grts_id for cell ids." )
185+ else :
186+ raise CommandError (
187+ "Shapefile must contain a GRTS_ID or grts_id column; "
188+ f"columns present: { ', ' .join (map (str , gdf .columns ))} "
189+ )
190+
170191 # Replace-on-reimport behavior: delete existing rows for any
171192 # (grts_cell_id, sample_frame_id) present in this import batch.
172- incoming_grts_ids = set (gdf ["GRTS_ID" ].dropna ().astype (int ).tolist ())
193+ incoming_grts_ids = set (gdf [grts_id_col ].dropna ().astype (int ).tolist ())
173194 if incoming_grts_ids :
174195 deleted_count , _ = GRTSCells .objects .filter (
175196 sample_frame_id = sample_frame_id ,
@@ -191,11 +212,11 @@ def handle(self, *args, **options): # noqa: C901, PLR0912, PLR0915
191212 total = len (gdf ),
192213 desc = f"Importing { sample_frame_id } " ,
193214 ):
194- # Hard fail if GRTS_ID is missing
195- if "GRTS_ID" not in row or row ["GRTS_ID" ] is None :
196- raise CommandError (f"Row { idx } missing required GRTS_ID field!" )
215+ # Hard fail if GRTS id is missing
216+ if grts_id_col not in row or row [grts_id_col ] is None :
217+ raise CommandError (f"Row { idx } missing required { grts_id_col } field!" )
197218
198- grts_id = int (row ["GRTS_ID" ])
219+ grts_id = int (row [grts_id_col ])
199220 cell_key = (grts_id , sample_frame_id )
200221 if cell_key in seen_in_file :
201222 continue
@@ -220,13 +241,13 @@ def handle(self, *args, **options): # noqa: C901, PLR0912, PLR0915
220241
221242 if len (records_to_create ) >= batch_size :
222243 with transaction .atomic ():
223- GRTSCells .objects .bulk_create (records_to_create , ignore_conflicts = True )
244+ GRTSCells .objects .bulk_create (records_to_create )
224245 records_to_create .clear ()
225246
226247 # Insert remaining records
227248 if records_to_create :
228249 with transaction .atomic ():
229- GRTSCells .objects .bulk_create (records_to_create , ignore_conflicts = True )
250+ GRTSCells .objects .bulk_create (records_to_create )
230251
231252 logger .info (
232253 "Finished importing shapefile for sample frame %s: %s new records" ,
0 commit comments