khushidhar1210 commited on
Commit
779693b
·
verified ·
1 Parent(s): feabc10

with crs and shx changes in the top

Browse files
Files changed (1) hide show
  1. app.py +27 -4
app.py CHANGED
@@ -10,14 +10,22 @@ from sentence_transformers import SentenceTransformer
10
  from transformers import AutoTokenizer, AutoModelForCausalLM
11
  import streamlit as st
12
 
13
- # Set the environment variables for GPU usage in Hugging Face
14
- os.environ["CUDA_VISIBLE_DEVICES"] = "0" # Hugging Face uses GPU 0 by default
15
- os.environ["TOKENIZERS_PARALLELISM"] = "false"
16
 
17
- # Set device to GPU if available
 
 
 
18
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
19
  st.write(f"Using device: {device}")
20
 
 
 
 
 
 
 
 
 
21
  # Step 1: Load and Process Floodland Data
22
  conn = sqlite3.connect('NY.db')
23
  cursor = conn.cursor()
@@ -25,12 +33,27 @@ cursor = conn.cursor()
25
  # Load shapefile
26
  gdf = gpd.read_file('S_FLD_HAZ_AR.shp')
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  # Validate geometries
29
  gdf['geometry'] = gdf['geometry'].apply(lambda geom: geom if geom.is_valid else None)
30
  gdf = gdf.dropna(subset=['geometry'])
31
 
32
  # Convert CRS to UTM Zone 18N (New York)
33
  gdf = gdf.to_crs(epsg=32618)
 
34
 
35
  # Calculate acreage (1 square meter = 0.000247105 acres)
36
  gdf['acreage'] = gdf.geometry.area * 0.000247105
 
10
  from transformers import AutoTokenizer, AutoModelForCausalLM
11
  import streamlit as st
12
 
 
 
 
13
 
14
+ # Set the SHAPE_RESTORE_SHX configuration option to YES (from previous fix)
15
+ os.environ['SHAPE_RESTORE_SHX'] = 'YES'
16
+
17
+ # Set device to GPU if available, otherwise CPU
18
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
19
  st.write(f"Using device: {device}")
20
 
21
+ # # Set the environment variables for GPU usage in Hugging Face
22
+ # os.environ["CUDA_VISIBLE_DEVICES"] = "0" # Hugging Face uses GPU 0 by default
23
+ # os.environ["TOKENIZERS_PARALLELISM"] = "false"
24
+
25
+ # # Set device to GPU if available
26
+ # device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
27
+ # st.write(f"Using device: {device}")
28
+
29
  # Step 1: Load and Process Floodland Data
30
  conn = sqlite3.connect('NY.db')
31
  cursor = conn.cursor()
 
33
  # Load shapefile
34
  gdf = gpd.read_file('S_FLD_HAZ_AR.shp')
35
 
36
+ #NEW PART
37
+
38
+ shapefile_path = os.path.join(os.path.dirname(__file__), 'S_FLD_HAZ_AR.shp')
39
+ gdf = gpd.read_file(shapefile_path)
40
+
41
+
42
+ # Check the initial CRS
43
+ st.write("Initial CRS:", gdf.crs)
44
+
45
+ # If the CRS is None, set it to WGS84 (EPSG:4326), which is common for FEMA shapefiles
46
+ if gdf.crs is None:
47
+ gdf.set_crs(epsg=4326, inplace=True)
48
+ st.write("CRS was missing; set to EPSG:4326 (WGS84).")
49
+
50
  # Validate geometries
51
  gdf['geometry'] = gdf['geometry'].apply(lambda geom: geom if geom.is_valid else None)
52
  gdf = gdf.dropna(subset=['geometry'])
53
 
54
  # Convert CRS to UTM Zone 18N (New York)
55
  gdf = gdf.to_crs(epsg=32618)
56
+ st.write("CRS after reprojection:", gdf.crs)
57
 
58
  # Calculate acreage (1 square meter = 0.000247105 acres)
59
  gdf['acreage'] = gdf.geometry.area * 0.000247105