Fer-geo commited on
Commit
867194d
·
1 Parent(s): e982217
.vscode/launch.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [{
4
+ "name": "Python: Streamlit",
5
+ "type": "python",
6
+ "request": "launch",
7
+ "module": "streamlit",
8
+ "env": {
9
+ "STREAMLIT_APP": "app.py",
10
+ "STREAMLIT_ENV": "development",
11
+ "AWS_PROFILE": "root",
12
+ "PYTHONPATH": "${workspaceRoot}/src",
13
+ },
14
+ "args": [
15
+ "run",
16
+ "D:/Terradot/huggingface/df_align/app.py"
17
+ ],
18
+ "jinja": true
19
+ }
20
+ ]
21
+ }
app.py CHANGED
@@ -32,8 +32,8 @@ st.sidebar.title('Proyecto Crea')
32
  st.sidebar.write('Solo uso interno')
33
  # add sidebar with 2 upload buttons
34
  st.sidebar.header('Upload Files')
35
- uploaded_file = st.sidebar.file_uploader('Upload your shapefile', type=['shp', 'geojson', 'json'])
36
- uploaded_file2 = st.sidebar.file_uploader('Upload your csv file', type=['csv'])
37
 
38
  if uploaded_file is not None:
39
  lotes_gdf = convert_to_gdf(uploaded_file)
@@ -118,46 +118,51 @@ if test:
118
  lotes_gdf['campo_obs'] = lotes_gdf['campo'].map(similar_dict)
119
 
120
  cutoff = 0.3
121
- for campo , df in lotes_gdf.groupby('campo'):
122
- for i, row in df.iterrows():
123
- c_obs = obs_df_2023.loc[obs_df_2023.Campo == row.campo_obs]
124
- lote_obs = c_obs.Lote.unique()
125
- # normalize the stings to lowercase and remove punctuation
126
- lote_obs_norm = [str(c).lower() for c in lote_obs]
127
- lote_obs_norm = [c.replace('.', ' ') for c in lote_obs_norm]
128
- similar_items = get_close_matches(row.lote, lote_obs_norm, N, cutoff)
129
- # get the index of the most similar item
130
- similar_items_idx = [lote_obs_norm.index(i) for i in similar_items]
131
-
132
- # get the most similar item in the original list
133
- similar_items = [lote_obs[i] for i in similar_items_idx]
134
-
135
- if similar_items:
136
- lotes_gdf.loc[i, 'lote_obs'] = similar_items[0]
137
- else:
138
- lotes_gdf.loc[i, 'lote_obs'] = "no match"
139
 
140
 
141
  def show_field(key):
 
 
 
142
  with col3:
143
  # st.header(st.session_state['key'])
144
  st.header('Lote')
145
- df_field = lotes_gdf[lotes_gdf['campo'] == st.session_state['key']]
146
  fields = df_field['lote'].unique().tolist()
147
- fields_obs = df_field['lote_obs'].unique().tolist()
148
  with st.form("fields_form"):
 
149
  for j,field in enumerate(fields):
150
- default = df_field[df_field['lote']==field]['lote_obs'].values[0]
151
- selected_value = st.multiselect(f'{field} (.shp):', fields_obs, default=default, key='field'+str(j))
152
-
153
- if st.form_submit_button("Submit"):
154
- for j,field in enumerate(fields):
155
- if selected_value:
156
- lotes_gdf.loc[(lotes_gdf['campo'] == st.session_state['key']) & (lotes_gdf['lote'] == field), 'lote_obs'] = selected_value[j]
157
- else:
158
- lotes_gdf.loc[(lotes_gdf['campo'] == st.session_state['key']) & (lotes_gdf['lote'] == field), 'lote_obs'] = 'no match'
159
 
160
- # st.dataframe(df.drop(columns=['geometry','nombre','apellido','campo','campo_obs']))
 
161
 
162
 
163
  def on_click(key):
@@ -169,14 +174,20 @@ if test:
169
  with col2:
170
  st.header('Campo')
171
  for i, key in enumerate(all_keys):
172
- # selected_value = st.selectbox(f'{key}:', campo_obs, index=campo_obs.index(similar_dict_df[similar_dict_df['gdf'] == key]['obs'].values[0]))
173
- selected_value = st.multiselect(f'{key} (.shp):', campo_obs, default=similar_dict_df[similar_dict_df['gdf'] == key]['obs'].values[0], key=i)
 
 
174
  if selected_value:
175
- similar_dict_df.loc[similar_dict_df['gdf'] == key, 'obs'] = selected_value[0]
 
 
176
  else:
177
- similar_dict_df.loc[similar_dict_df['gdf'] == key, 'obs'] = 'no match'
 
 
178
 
179
- st.button('Show Fields', key=key, on_click=on_click(key))
180
 
181
 
182
  # st.dataframe(similar_dict_df)
@@ -191,7 +202,7 @@ if test:
191
  st.sidebar.download_button(
192
  label="Download GeoJSON",
193
  data=lotes_gdf.to_json().encode('utf-8'),
194
- file_name='lotes.geojson',
195
  # mime='text/csv',
196
  mime = 'application/json',
197
  )
 
32
  st.sidebar.write('Solo uso interno')
33
  # add sidebar with 2 upload buttons
34
  st.sidebar.header('Upload Files')
35
+ uploaded_file = st.sidebar.file_uploader('Upload your shapefile', type=['shp', 'geojson', 'json'], disabled = True)
36
+ uploaded_file2 = st.sidebar.file_uploader('Upload your csv file', type=['csv'], disabled = True)
37
 
38
  if uploaded_file is not None:
39
  lotes_gdf = convert_to_gdf(uploaded_file)
 
118
  lotes_gdf['campo_obs'] = lotes_gdf['campo'].map(similar_dict)
119
 
120
  cutoff = 0.3
121
+ # for campo , df in lotes_gdf.groupby('campo'):
122
+ # for i, row in df.iterrows():
123
+ # c_obs = obs_df_2023.loc[obs_df_2023.Campo == row.campo_obs]
124
+ # lote_obs = c_obs.Lote.unique()
125
+ # # normalize the stings to lowercase and remove punctuation
126
+ # lote_obs_norm = [str(c).lower() for c in lote_obs]
127
+ # lote_obs_norm = [c.replace('.', ' ') for c in lote_obs_norm]
128
+ # similar_items = get_close_matches(row.lote, lote_obs_norm, N, cutoff)
129
+ # # get the index of the most similar item
130
+ # similar_items_idx = [lote_obs_norm.index(i) for i in similar_items]
131
+
132
+ # # get the most similar item in the original list
133
+ # similar_items = [lote_obs[i] for i in similar_items_idx]
134
+
135
+ # if similar_items:
136
+ # lotes_gdf.loc[i, 'lote_obs'] = similar_items[0]
137
+ # else:
138
+ # lotes_gdf.loc[i, 'lote_obs'] = "no match"
139
 
140
 
141
  def show_field(key):
142
+ key, selected_value = key
143
+ lote_obs = obs_df_2023[obs_df_2023['Campo'] == selected_value]['Lote'].unique().tolist()
144
+ lote_obs.insert(0, 'no match')
145
  with col3:
146
  # st.header(st.session_state['key'])
147
  st.header('Lote')
148
+ df_field = lotes_gdf[lotes_gdf['campo'] == key]
149
  fields = df_field['lote'].unique().tolist()
150
+
151
  with st.form("fields_form"):
152
+
153
  for j,field in enumerate(fields):
154
+ similar_items = get_close_matches(field, lote_obs, 3, 0.70)
155
+ default = similar_items[0] if similar_items else 'no match'
156
+ # selected_value = st.multiselect(f'{field} (.shp):', lote_obs, default=default, key='field'+str(j))
157
+ selected_value = st.selectbox(f'{field} (.shp):', lote_obs, index = lote_obs.index(default) , key='field'+str(j))
158
+
159
+ # if selected_value:
160
+ # lotes_gdf.loc[(lotes_gdf['campo'] == key) & (lotes_gdf['lote'] == field), 'lote_obs'] = selected_value
161
+ # else:
162
+ lotes_gdf.loc[(lotes_gdf['campo'] == key) & (lotes_gdf['lote'] == field), 'lote_obs'] = default
163
 
164
+ if st.form_submit_button("Submit"):
165
+ st.dataframe(lotes_gdf.drop(columns=['geometry','nombre','apellido','campo','campo_obs']))
166
 
167
 
168
  def on_click(key):
 
174
  with col2:
175
  st.header('Campo')
176
  for i, key in enumerate(all_keys):
177
+ selected_value = st.selectbox(f'{key}:', campo_obs, index=campo_obs.index(similar_dict_df[similar_dict_df['gdf'] == key]['obs'].values[0]))
178
+ # selected_value = st.multiselect(f'{key} (.shp):', campo_obs, default=similar_dict_df[similar_dict_df['gdf'] == key]['obs'].values[0], key=i)
179
+ lotes_gdf.loc[(lotes_gdf['campo'] == key) & (lotes_gdf['empresa'] == selected_company), 'campo_obs'] = similar_dict_df[similar_dict_df['gdf'] == key]['obs'].values[0]
180
+
181
  if selected_value:
182
+ similar_dict_df.loc[similar_dict_df['gdf'] == key, 'obs'] = selected_value
183
+ value = selected_value
184
+ lotes_gdf.loc[(lotes_gdf['campo'] == key) & (lotes_gdf['empresa'] == selected_company), 'campo_obs'] = selected_value
185
  else:
186
+ # similar_dict_df.loc[similar_dict_df['gdf'] == key, 'obs'] = 'no match'
187
+ value = similar_dict_df.loc[similar_dict_df['gdf'] == key, 'obs']
188
+ lotes_gdf.loc[(lotes_gdf['campo'] == key) & (lotes_gdf['empresa'] == selected_company), 'campo_obs'] = value
189
 
190
+ st.button('Show Fields', key=key, on_click=on_click([key,value]))
191
 
192
 
193
  # st.dataframe(similar_dict_df)
 
202
  st.sidebar.download_button(
203
  label="Download GeoJSON",
204
  data=lotes_gdf.to_json().encode('utf-8'),
205
+ file_name=f'{selected_company}.geojson',
206
  # mime='text/csv',
207
  mime = 'application/json',
208
  )
data/lotes espacio crea_empresa.dbf CHANGED
Binary files a/data/lotes espacio crea_empresa.dbf and b/data/lotes espacio crea_empresa.dbf differ